0

I am doing testing and below is a piece of code that is giving me an error : Unhandled exception at 0x00956faa in myprogram.exe: 0xC0000005: Access violation reading location 0xcccccccc.

The function is:

ECommand(unsigned char CBuffer[], const CDBuffer_t * const SdBuffer_Ptr) 

The piece of code:

unsigned char CBuffer[11];
memset(CBuffer,0,sizeof(uint8_t)*4);
CBuffer[2] = 0x02;
CDBuffer_t sendBuffer;
sdBuffer.buffer = static_cast<uint8_t *>(malloc(sizeof(uint8_t)*8));
memset(sdBuffer.buffer,0,sizeof(uint8_t)*8);
CBuffer[6] = 0x02;
ECommand(CBuffer,&sdBuffer);

getting error at:

ECommand(CBuffer,&sdBuffer);

Also

typedef struct CDBuffer_t
{
uint8_t *buffer; 
uint16_t count; 
uint16_t size; 
uint16_t status; 
} CDBuffer_t;

If any more info is required let me know. I know its something to do with memory accessing but am not able to figure it out please help me get rid of the program crashing because of above exception Thanks

  • This code looks more C than C++ (using `malloc` and not `new`). – SurvivalMachine Aug 12 '16 at 15:38
  • 1
    @SurvivalMachine: you shouldn't use `new` in C++, either ;) Except for very few very special cases. – Violet Giraffe Aug 12 '16 at 15:41
  • ya actually the main code is in c and for testing c++ is used – mentaal coder Aug 12 '16 at 15:41
  • @VioletGiraffe true, I didn't say that `malloc` or `new` is needed here. – SurvivalMachine Aug 12 '16 at 15:46
  • Impossible to say without knowing what `ECommand` requires of its parameters. – molbdnilo Aug 12 '16 at 15:47
  • What more Info is required like ECommand whole function? or something from it @molbdnilo – mentaal coder Aug 12 '16 at 15:54
  • @mentaalcoder Since you're testing, don't you have access to the developer of `ECommand` and can ask them if you're using it correctly, or at least its documentation? It's impossible for outsiders to guess whether the problem lies with the testing code or whether you have found a bug in `ECommand`. (That you're not initialising all of `sendBuffer` looks very fishy, though.) – molbdnilo Aug 12 '16 at 16:07

0 Answers0