Pointer-related issue yet still is FAT12-related.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
eXeCuTeR
Member
Member
Posts: 63
Joined: Tue Dec 09, 2008 12:43 pm

Pointer-related issue yet still is FAT12-related.

Post by eXeCuTeR »

Code: Select all

fat_entry_t *fat_handle_new_entry(fat_entry_t *parent, unsigned char *entry, fat_entry_t *prev)
{
 if(fat_entry_exist(entry))
 {
   fat_entry_t *fat_entry = (fat_entry_t *)malloc(sizeof(fat_entry_t));
   memcpy((void *)fat_entry, (void *)entry, FAT_DIR_ENTRY_LENGTH);

   fat_entry->parent = parent;
   if(prev != parent)
    prev->next = fat_entry;
   else
    parent->first_child = fat_entry;
   return fat_entry;
 }
 return 0;
}
the problem is that fat_entry doesn't hold anything after the loop exists (neither do buf which point to the same place)
I also tried as a replacment for the memcpy call:

Code: Select all

int i = 0;
unsigned char *buf = (unsigned char *)fat_entry;
for(;i<FAT_DIR_ENTRY_LENGTH;i++) buf[i] = entry[i];
When trying to display fat_entry->filename (which is 8 bytes long and first member of fat_entry_t struct), it doesn't show anything outside the loop (after it).
Also, when displaying the buf outside the loop it doesn't work.

only when displaying these INSIDE the loop (either fat_entry and buf) it shows the correct data.
Also, I checked and they both point to the same place in any place of this function.

So what the hell happens when loop exists to my memory?
ANY IDEAS? Thanks in advance!
Last edited by eXeCuTeR on Tue Jul 20, 2010 7:38 am, edited 1 time in total.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Pointer-related issue yet still is FAT12-related.

Post by gerryg400 »

They are local variables to the loop.
If a trainstation is where trains stop, what is a workstation ?
eXeCuTeR
Member
Member
Posts: 63
Joined: Tue Dec 09, 2008 12:43 pm

Re: Pointer-related issue yet still is FAT12-related.

Post by eXeCuTeR »

gerryg400 wrote:They are local variables to the loop.
They are not mate, look at the code again.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Pointer-related issue yet still is FAT12-related.

Post by gerryg400 »

They are not mate, look at the code again.
Do I really have to ? Well since you asked so nicely. What, exactly should I look at ?

I see an if statement with 2 local variables (one of which seems to be of the wrong type - does this code compile?). But you gave no information about how you 'displayed' the values of the 2 variables, nor where exactly in the code the values were checked. My guess was entirely reasonable.
If a trainstation is where trains stop, what is a workstation ?
eXeCuTeR
Member
Member
Posts: 63
Joined: Tue Dec 09, 2008 12:43 pm

Re: Pointer-related issue yet still is FAT12-related.

Post by eXeCuTeR »

gerryg400 wrote:
They are not mate, look at the code again.
Do I really have to ? Well since you asked so nicely. What, exactly should I look at ?

I see an if statement with 2 local variables (one of which seems to be of the wrong type - does this code compile?). But you gave no information about how you 'displayed' the values of the 2 variables, nor where exactly in the code the values were checked. My guess was entirely reasonable.
I checked their values with a bunch of printf's thrown in the function in different location, that's it.
Inside the loop, the values were shown perfectly but when it exited it, they were no longer shown.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Pointer-related issue yet still is FAT12-related.

Post by gerryg400 »

But where's the loop?
If a trainstation is where trains stop, what is a workstation ?
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Pointer-related issue yet still is FAT12-related.

Post by Gigasoft »

Could it be that you are allocating the same physical pages repeatedly?

Or that malloc is allocating from some place it shouldn't?
Post Reply