LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-08-2005, 11:18 PM   #1
tara
Member
 
Registered: Aug 2005
Location: Australia
Distribution: Mageia 1
Posts: 53

Rep: Reputation: 15
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

Last edited by tara; 11-08-2005 at 11:19 PM.
 
Old 11-08-2005, 11:40 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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"

Last edited by paulsm4; 11-08-2005 at 11:43 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Way to Get at Extra Bit of High Memory? IamI Slackware 4 04-21-2005 11:04 PM
IPC Memory Share - C Program - Why not exiting for(;;) ?? brunnopessoa Programming 4 09-05-2004 09:27 PM
USB Flash memory writing problem tajuton Linux - Hardware 8 02-18-2004 02:17 AM
Standard Way To Share Memory Among Processes? Sys-V IPC? overbored Programming 1 06-21-2003 01:33 PM
IPC Shared Memory support in kernel? stevho Linux - General 1 01-17-2002 07:48 PM


All times are GMT -5. The time now is 06:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration