MSC5.1: bug in realloc() ???

Mark Roberts markro at microsoft.UUCP
Sat Nov 5 10:20:48 AEST 1988


In article <2310001 at hprnd.HP.COM> pyt at hprnd.HP.COM (Pierre-Yves Thoulon) writes:
|I've recently had trouble with the realloc function in the Microsoft C v5.1
|
|struct FileInfo 
|{
|    char Dummy0; /* so the unsigned be correctly aligned on word boudary */
|    char Attrib;
|    ...
|    char Name[13];
|    char Dummy1; /* so next structure in array will be on word boundary */
|};
|    memcpy(&Files[FileNum++].Attrib,&DosReturn.attrib,sizeof(struct FileInfo));

I suggest the problem is with your code sample.

You are copying sizeof(struct FileInfo) but that includes your two Dummy chars.
How about (sizeof(FileInfo)-2) or (sizeof(FileInfo)-2*sizeof(char)) if you want
to be REAL portable.

Glad to be of help.



More information about the Comp.lang.c mailing list