2000-10-26 23:03:09

by J.A. Magallon

[permalink] [raw]
Subject: Re: Problem with msgsnd


On Thu, 26 Oct 2000 17:15:30 Marc Schneider wrote:
> [email protected] wrote:
> >
> > Marc Schneider wrote:
> > >
> > > msgsnd seems to be corrupting memory around the msgbuf pointer.
> > >
> > > for example I have the following code:
> > >
> > > pMsgBuf = malloc(iPacketLen + 4 + 8);
> > > bzero(pMsgBuf, iPacketLen + 4 + 8);
> > > pMsgBuf += 4; /* Build a guard band */
> > >
> > > printf("PMQ:pMsgBuf: %p\n",pMsgBuf);
> > > printf("PMQ:-4: %p\n", *(pMsgBuf-4));
> > >

Silly question: why do you :

printf("PMQ:-4: %p\n", *(pMsgBuf-4));

instead of:
!!!
printf("PMQ:-4: %d\n", *(pMsgBuf-4));, or whatever applies...(typeof pMsgBuf?)

If you use %p, printf expects a pointer in stack, and depending on type of
pMsgBuf (is a char * ?), *pMsgBuf can be passed as a char (I don't think so,
C passes chars as ints, and I dont remenber any kind of option to modify this)
or a short or an int...

So, perhaps you dont put enough data on stack for a pointer and printf gets
incorrect data (the zero in pMsgBuf plus the return value that stored in rc...).

--
Juan Antonio Magallon Lacarta mailto:[email protected]