Discussion:
HeapAlloc crashes in wcsncpy
(too old to reply)
Rohit
2008-10-17 06:31:56 UTC
Permalink
I am using a procedure which calls HeapAlloc to allocate memory.

void myAlloc(DWORD Size)
{
if ( Size > 0 ) {
char *Temp;
Temp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (DWORD) Size);
return Temp;
}
else
return (void *)0;
}

And the call to this function is :

myVar = (structname *)myAlloc( sizeof(structvar));

This sometimes gives me a crash and analysing Dr.Watson logs, stack
can be traced as

ntdll!wcsncpy+0x74f

for call to : myAlloc->wcsncpy

Can anyone comment ?
Alex Blekhman
2008-10-17 08:00:33 UTC
Permalink
Post by Rohit
I am using a procedure which calls HeapAlloc to allocate memory.
void myAlloc(DWORD Size)
{
if ( Size > 0 ) {
char *Temp;
Temp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (DWORD)
Size);
return Temp;
}
else
return (void *)0;
}
myVar = (structname *)myAlloc( sizeof(structvar));
This sometimes gives me a crash and analysing Dr.Watson logs,
stack can be traced as
ntdll!wcsncpy+0x74f
for call to : myAlloc->wcsncpy
Can anyone comment ?
The code you posted makes no sense at all. The `myAlloc' function
won't even compile.

Alex
Rohit
2008-10-20 07:21:39 UTC
Permalink
Post by Alex Blekhman
Post by Rohit
I am using a procedure which calls HeapAlloc to allocate memory.
void myAlloc(DWORD Size)
{
if ( Size > 0 ) {
char  *Temp;
Temp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (DWORD)
Size);
return Temp;
 }
 else
return (void *)0;
}
myVar = (structname *)myAlloc( sizeof(structvar));
This sometimes gives me a crash and analysing Dr.Watson logs,
stack can be traced as
ntdll!wcsncpy+0x74f
for call to : myAlloc->wcsncpy
Can anyone comment ?
The code you posted makes no sense at all. The `myAlloc' function
won't even compile.
Alex- Hide quoted text -
- Show quoted text -
Ya .. it was a typo mistake .. Its void* instead of void .

Further .....

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;
Manish Agarwal
2008-10-23 05:25:38 UTC
Permalink
again typos in structname defination :)

correct typedef should be something like-


typedef struct structname {
int SignalCode;
structname *Pre, *Suc;
int Sender;
void *SigP;
int SignalId;
int IsTimer;
int TimerTime;
int TimerToSetOrReset;
bool (* yEq)();
bool TestParams;
structname *Param;
}
Post by Alex Blekhman
Post by Rohit
I am using a procedure which calls HeapAlloc to allocate memory.
void myAlloc(DWORD Size)
{
if ( Size > 0 ) {
char *Temp;
Temp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (DWORD)
Size);
return Temp;
}
else
return (void *)0;
}
myVar = (structname *)myAlloc( sizeof(structvar));
This sometimes gives me a crash and analysing Dr.Watson logs,
stack can be traced as
ntdll!wcsncpy+0x74f
for call to : myAlloc->wcsncpy
Can anyone comment ?
The code you posted makes no sense at all. The `myAlloc' function
won't even compile.
Alex- Hide quoted text -
- Show quoted text -
Ya .. it was a typo mistake .. Its void* instead of void .

Further .....

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;

Loading...