Sign in to follow this  
deftware

Malloc returns unindexable memory ????

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.

-me

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this