Re: HeapAlloc Crashes in wcsncpy
On Oct 17, 12:01 pm, Ulrich Eckhardt <eckha...@satorlaser.com> wrote:
Rohit wrote:
I am using a procedure which calls HeapAlloc to allocate memory.
void myAlloc(DWORD Size)
This function returns nothing...
{
if ( Size > 0 ) {
char *Temp;
Temp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (DWORD) =
Size);
return Temp;
}
else
return (void *)0;
}
... but has return statements with an argument. Post your real code,
anything else is just useless guessing from here on. In any case though,
take care of the following points first:
1. Tell us what language you are using.
2. Avoid casts. In C, they should rarely be necessary, in C++ using C-sty=
l
casts is usually wrong.
And the call to this function is :
myVar = (structname *)myAlloc( sizeof(structvar));
FYI: 'sizeof' yields a 'size_t', which is also the argument that an
allocation function should take. Further, I sense a disagreement between
the type you cast to and the size requested.
for call to : myAlloc->wcsncpy
'myAlloc' is a function, so that expression makes zero sense.
Provide relevant info, to make it possible for you to get help.
Uli
--
C++ FAQ:http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch=E4ftsf=FChrer: Thorsten F=F6cking, Amtsgericht Hamburg HR B62 932
Ya .. it was a typo mistake .. Its void* instead of void .
typedef struct structname {
int SignalCode;
strcutname Pre, Suc;
int Sender;
void *SigP;
int SignalId;
int IsTimer;
int TimerTime;
int TimerToSetOrReset;
bool (* yEq)();
bool TestParams;
strctname Param;
} structvar;
for xAlloc - wcsncpy i meant that drwatson crash dump stack analysis
shows call to myAlloc then crashing in wcsncpy. This code is written
as a part of a test.c file.