Page 1 of 1

Blank return values from function.

Posted: Thu Sep 04, 2014 3:54 pm
by SlayterDev
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: Select all

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

Re: Blank return values from function.

Posted: Thu Sep 04, 2014 3:59 pm
by Nable
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?

Re: Blank return values from function.

Posted: Thu Sep 04, 2014 4:40 pm
by SlayterDev
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.

Re: Blank return values from function.

Posted: Thu Sep 04, 2014 4:53 pm
by SlayterDev
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.

Re: Blank return values from function.

Posted: Thu Sep 04, 2014 5:22 pm
by SlayterDev
Disregard this. I'm retarded and don't know what negative values are.