OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 5:10 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Blank return values from function.
PostPosted: Thu Sep 04, 2014 3:54 pm 
Offline
Member
Member

Joined: Wed Aug 13, 2014 4:22 pm
Posts: 25
I'm in the middle of writing a simple FAT12 driver. When I open the file i compare the name of the file I'm looking for to the name of the file in the drive as I iterate through the root directory. Easy right? apparently not.

When I make a simple call to strcmp(), nothing comes back. I try to print the return value and it prints nothing as if there is nothing in the variable. It doesn't print garbage data, it literally prints nothing. Here is the relevant piece of code:

Code:
FILE file;
   unsigned char *buf;
   PDIRECTORY directory;

   char dosFileName[11];
   to_dos_file_name(directoryName, dosFileName, 11);
   dosFileName[11] = 0; // null terminate

   for (int sector = 0; sector < 14; sector++) {
      // read sector
      buf = (unsigned char *)flpy_read_sector(mount_info.rootOffset + sector);

      directory = (PDIRECTORY)buf;

      // 16 entries per sector
      for (int i = 0; i < 16; i++) {
         // get current filename
         char name[11];
         memcpy(name, directory->filename, 11);
         name[11] = 0;

         // does it match?
         if (!strcmp(dosFileName, name)) { // if I print this value, nothing shows up


Also when I have it as above (i think, i've been moving things around a lot) the dosFileName string gets over written or something and also becomes a disappearing value. From debugging I know dosFileName is intact until i memcpy() the directory->filename. Any ideas what is causing this madness? Thanks


Top
 Profile  
 
 Post subject: Re: Blank return values from function.
PostPosted: Thu Sep 04, 2014 3:59 pm 
Offline
Member
Member

Joined: Tue Nov 08, 2011 11:35 am
Posts: 453
Array with 11 elements has only indexes 0..10 and you put null-terminator into 11'th, so you are ~definitely overwrite something. For string of 11 chars you need array with length=12. Is it clear?


Top
 Profile  
 
 Post subject: Re: Blank return values from function.
PostPosted: Thu Sep 04, 2014 4:40 pm 
Offline
Member
Member

Joined: Wed Aug 13, 2014 4:22 pm
Posts: 25
Yeah I should've caught that. I fixed the buffers to hold 12 each but now unless the value is 1, the return value of strcmp() still disappears.


Top
 Profile  
 
 Post subject: Re: Blank return values from function.
PostPosted: Thu Sep 04, 2014 4:53 pm 
Offline
Member
Member

Joined: Wed Aug 13, 2014 4:22 pm
Posts: 25
Printing the hex value of the strcmp() return value shows that in the cases where it doesn't show up, the hex value is 0xFFFFFFFF. This is even after I limit it to -1 to 1. What gives.


Top
 Profile  
 
 Post subject: Re: Blank return values from function.
PostPosted: Thu Sep 04, 2014 5:22 pm 
Offline
Member
Member

Joined: Wed Aug 13, 2014 4:22 pm
Posts: 25
Disregard this. I'm retarded and don't know what negative values are.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 121 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group