Unhandled exception : Access violation reading location error help needed

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.

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



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);



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

If any more infor is required let me know. I know its something to do with memory accessing
please help me get rid of the program crashing because of above exception
Thanks
Edit: pl check below for helping for error solving thanks
Last edited on
1
2
unsigned char CBuffer[11];
memset(CBuffer,0,sizeof(uint8_t)*4);

Why are you only setting part of your buffer to zero?

Did you try running the program with your debugger? The debugger should be able to tell you exactly where it detected the problem and should allow you to view the variables at the time of the crash.

I am getting error form the line ECommand(CBuffer,&sdBuffer); dont know whats wrong with it

Since you posted so little code I can only guess, but with that guess I would say that instead of passing a pointer to your sdBuffer you were passing a pointer to a pointer to your sdBuffer. What do the variables look like in your debugger?

Also why are you using malloc() instead of new/delete?

Hi what other part of code is required let me know I am new to this and interning at a company so not able to solve also any other debugging tips or some advice will be appreciated
thanks for the reply
Hi what other part of code is required let me know

Since you seem to be getting a segmentation fault, a small complete program that illustrates the problem would be helpful.

Have you run the program with your debugger? The debugger should tell you exactly where it detects the problem and you should be able to view the variables at the time of the crash.

My mentor took that part to solve for me but I got stuck again in different part below is whole code and req things

1
2
3
C_Channel * const c_Ptr = NULL;
C_Input * const input_Ptr = NULL;
esCb(NULL, NULL);


I am getting error : 0xC0000005: Access violation reading location 0x00000000 at esCb(NULL, NULL);

struct C_Channel
{
Unsigned char qt-1;
.......
Unsigned char qt-32;
}

typedef union C_Input
{
CBuf_t buffer_p;
} C_Input;

typedef struct CBuf_t
{
unsigned char *buffer;
unsigned char rndm2;
unsigned char rndm3;
unsigned char rndm4;
}

I think I am making mistake in Initializing can you tell me how to initialize or get rid of the error thanks
Topic archived. No new replies allowed.