PDDuino
PDDuino copied to clipboard
loop index off-by-one in return_reference
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