Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

realloc worked in an MFC DLL, but not here

Status
Not open for further replies.

apatterno

Programmer
Nov 26, 2002
368
US
The following code worked in an MFC dll, but when I moved it to a non-MFC DLL, the realloc function returns NULL.

[tt]void MD::nullstr()
{
if (((char*)data)[len-1] != 0) {
// at this location, data points to a valid address
// and len == 9

data = realloc(data,len+1);
// at this location, data == NULL
((char*)data)[len] = 0;
// the preceding line causes a memory fault, of course.
len++;
}
}
[/tt]

I don't understand why the realloc fails-- data points to valid memory, and len is equal to 9. I simply want to change the allocation size to 10, and store the new pointer in data.

This worked in an MFC DLL, but not in a normal DLL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top