Jump to content
  • Advertisement
Sign in to follow this  

Malloc returns unindexable memory ????

This topic is 3212 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a problem that seems to be highly unusual. I malloc a piece of memory, then try to index into it and save a pointer to that, but when I try to access a member of that structure my program crashes.. Here's a screenshot that should clarify: as you can see, my index "function" is zero, then it goes on to store a pointer to "function" indexing "exefuncs".. this goes well, as you can see the 'a' character ouputted in the window. then the program neither outputs 'b' or 'c' as it has obviously crashed when trying to access the "s_exefunc" member "firststatement".. this makes zero sense to me. I have no clue why it wouldn't be working, unless malloc is br0k3n any hints ?

Share this post

Link to post
Share on other sites
The code you posted doesn't show any malloc. It just shows that the pointer stored in your exefuncs array is NULL.

Post the code where you load your exefuncs array with valid whatevers.

It's not working because one of these:
(a) you didn't actually store stuff in hte exefuncs array
(b) something else set it back to NULL

Anyway, post the relevant code.


Share this post

Link to post
Share on other sites

hahahaha.. sorry guys, let this be a lesson to all-night coders:


s_exefunc *exefuncs=0;

...somewhere in another function..

//function datas
fread(&exefunc_size, 2, 1, exec);
exefunc_size *= sizeof(s_exefunc);
printf("exefunc_size %d bytes\n", exefunc_size);
exefuncs = (s_exefunc *)malloc(exefunc_size);
fread(&exefuncs, exefunc_size, 1, exec);


please note the ampersand preceding "exefuncs" in the 2nd fread call.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!