bkw777 / PDDuino

A hardware emulator of the Tandy Portable Disk Drive using an SD card for mass storage
GNU General Public License v3.0
27 stars 4 forks source link

loop index off-by-one in return_reference #1

Open go4retro opened 3 years ago

go4retro commented 3 years ago

In return_reference

for(byte i=0x00; i < 0x07; i++){ //Find the end of the directory's name by looping through the name buffer
  if(tempRefFileName[i] == 0x00) term = i; //and setting a termination index to the offset where the termination is encountered
}

Goes up to 7. So, if I have a dir of name:

12345678

the loop will end at i=7 and the if statement would never be true. Thus, the loop can be "i<6", since term = 6 at the beginning of the loop. It doesn't hurt anything, though, it looks like.

But, even with the change, there's an issue, I believe. If the dir name is "jim", the check is tru at i=3 (term will be set to 3), but the check does not break out of the loop. The check is then true at 4, and term gets updated. IN this case, for any dir name < 6, term will always end up at 6 (in the above loop, with i being checked for < 7).

However, the later code:

tempRefFileName[term++] = '.';  //Tack the expected ".<>" to the end of the name
tempRefFileName[term++] = '<';
tempRefFileName[term++] = '>';

will put the extension at positions 6,7,8 (bytes 7,8,9), leaving 0-5 nuls in between. Evidently, ts-dos is OK with this, but I think it should be spaces, and I think the code planned to turn jim into "jim.<>", not "jim\0\0\0.<>"

I would change the loop to "i<6" and break out of the loop if the check for null succeeds.

Jim