471,601 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,601 software developers and data experts.

Access violation - Malloc problem

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
Jul 22 '05 #1
3 5697
"Rossel NathanaŽl" <na**************@gem-ag.com> writes:

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
--
| Nicolas Pavlidis | Elvis Presly: |\ |__ |
| Student of SE & KM | "Into the goto" | \|__| |
| pa****@sbox.tugraz.at | ICQ #320057056 | |
|-------------------University of Technology, Graz----------------|
Jul 22 '05 #2

"Rossel NathanaŽl" <na**************@gem-ag.com> wrote in message
news:41********@news.bluewin.ch...
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
Jul 22 '05 #3
The problem has been resolve. They was a malloc(8) in an other function and
a strcpy with 9 character ('\0').

"Rossel NathanaŽl" <na**************@gem-ag.com> a ťcrit dans le message de
news:41********@news.bluewin.ch...
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

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Steven Reddie | last post: by
3 posts views Thread by paulrc_25 | last post: by
14 posts views Thread by spl | last post: by
39 posts views Thread by Martin | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.