lfnInfo = (fat_longfilename *) &fileinfo[i&0xF];\r
if(lfnInfo->id & 0x40) {\r
memset(lfn, 0, 256);\r
- lfnPos = 255;\r
+ lfnPos = (lfnInfo->id & 0x3F) * 13 - 1;\r
}\r
+ // Sanity check the position so we don't overflow\r
+ if( lfnPos < 12 )\r
+ continue ;\r
lfn[lfnPos--] = lfnInfo->name3[1]; lfn[lfnPos--] = lfnInfo->name3[0];\r
lfn[lfnPos--] = lfnInfo->name2[5]; lfn[lfnPos--] = lfnInfo->name2[4];\r
lfn[lfnPos--] = lfnInfo->name2[3]; lfn[lfnPos--] = lfnInfo->name2[2];\r
lfn[lfnPos--] = lfnInfo->name1[0];\r
if((lfnInfo->id&0x3F) == 1)\r
{\r
- memcpy(lfn, lfn+lfnPos+1, 256-lfnPos);\r
lfnId = i+1;\r
}\r
}\r