Page 1 of 1

Pointer-related issue yet still is FAT12-related.

Posted: Mon Jul 19, 2010 7:58 pm
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!

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

Posted: Mon Jul 19, 2010 9:11 pm
by gerryg400
They are local variables to the loop.

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

Posted: Tue Jul 20, 2010 6:27 am
by eXeCuTeR
gerryg400 wrote:They are local variables to the loop.
They are not mate, look at the code again.

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

Posted: Tue Jul 20, 2010 7:24 am
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.

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

Posted: Tue Jul 20, 2010 8:01 am
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.

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

Posted: Tue Jul 20, 2010 8:24 am
by gerryg400
But where's the loop?

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

Posted: Tue Jul 20, 2010 10:37 am
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?