Access violation - Malloc problem

  • Thread starter Rossel Nathanaël
  • Start date
R

Rossel Nathanaël

146: unsigned short *sDate;
147:
148: sDate = (unsigned short *)malloc(100);
17E4157C 6A 64 push 64h
17E4157E E8 05 4C 00 00 call malloc (17e46188)
17E41583 83 C4 04 add esp,4
17E41586 89 45 FC mov dword ptr [sDate],eax


When running only the line 17E4157E (malloc), I get next error :

First Chance Exception in : 0xC0000005: Access Violation
 
N

Nicolas Pavlidis

Maybe a litle bit information of the code following to the malloc call
would be helpfull!
146: unsigned short *sDate;
147:
148: sDate = (unsigned short *)malloc(100);

Try to write this line another way:
sDate=(unsigned chort*) malloc(100 * sizeof(unsigned short));

BTW this is a c++ newsgroup and so the following thing would be better
in C++:

sDate = new unsigned short[100]; ;-)

HTH && Kind regards,
Nicolas
 
J

John Harrison

Rossel Nathanaël said:
146: unsigned short *sDate;
147:
148: sDate = (unsigned short *)malloc(100);
17E4157C 6A 64 push 64h
17E4157E E8 05 4C 00 00 call malloc (17e46188)
17E41583 83 C4 04 add esp,4
17E41586 89 45 FC mov dword ptr [sDate],eax


When running only the line 17E4157E (malloc), I get next error :

First Chance Exception in : 0xC0000005: Access Violation

Your heap has been corrupted by some earlier bug in your code.

john
 
R

Rossel Nathanaël

The problem has been resolve. They was a malloc(8) in an other function and
a strcpy with 9 character ('\0').
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top