LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   IPC msgrcv - writing overflows memory extra 4 bytes (https://www.linuxquestions.org/questions/programming-9/ipc-msgrcv-writing-overflows-memory-extra-4-bytes-381317/)

tara 11-08-2005 11:18 PM

IPC msgrcv - writing overflows memory extra 4 bytes
 
Hi

I have the following structure:


#define ZZ_SIMMSG_DATA_SIZE 1000

struct T_simmsg
{
long mtype;
int src;
int dest;
int length; // length of used data area

union
{
int ex_num;
int display_num;
};

unsigned char data[ZZ_SIMMSG_DATA_SIZE];
};



In another file I have the following code:


struct T_simmsg rx_msg

result = msgrcv(msqid, &rx_msg, sizeof(rx_msg), ZZ_TASK_STARTED, IPC_NOWAIT);


I am using a memory tool check that checks for memory leaks, write and read overflows etc...

The above code causes a "writing overflows memory" error. Where the rx_msg has a size of 1020 my program seems to want to write 1024? Whatever the value of 'ZZ_SIMMSG_DATA_SIZE + 20' there is always an extra 4 bytes.

When I put a printf statement for the size of rx_msg it returns 'ZZ_SIMMSG_DATA_SIZE + 20', as expected

Can anyone tell me why?? and how do I fix it

thank you
Tara

paulsm4 11-08-2005 11:40 PM

Hi -

Are you coding any of this in C++? Do you think there's any chance you might accidentally be introducing a (32-bit, 4-byte) C++ "this" pointer somewhere in your code?

Just a shot in the dark, but...

PS:
One good way to find out is:

1. Reproduce the problem in as small a test module as possible
2. Make sure your test case has some code that actually accesses
data in the offending struct or buffer
3. Compile the module with "gcc -S" to get assembler output
4. Look at the assembly output to see which access is "off by four"


All times are GMT -5. The time now is 04:07 PM.