🐛 Fix long filename read/report (#25509)

This commit is contained in:
Eduard Sukharev
2023-03-15 00:49:49 +03:00
committed by Scott Lahteine
parent ccb4d11696
commit ea6430ddf6

View File

@@ -1013,8 +1013,7 @@ bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) {
* \return false if the dirname is a short file name 8.3 (SFN)
*/
bool SdBaseFile::isDirNameLFN(const char *dirname) {
uint8_t length = strlen(dirname);
uint8_t idx = length;
uint8_t length = strlen(dirname), idx = length;
bool dotFound = false;
if (idx > 12) return true; // LFN due to filename length > 12 ("filename.ext")
// Check dot(s) position
@@ -1508,8 +1507,8 @@ int8_t SdBaseFile::readDir(dir_t *dir, char *longFilename) {
if (DIR_IS_FILE_OR_SUBDIR(dir)) {
#if ENABLED(UTF_FILENAME_SUPPORT)
#if LONG_FILENAME_CHARSIZE > 2
// Add warning for developers for currently not supported 3-byte cases (Conversion series of 2-byte
// codepoints to 3-byte in-place will break the rest of filename)
// Add warning for developers for unsupported 3-byte cases.
// (Converting 2-byte codepoints to 3-byte in-place would break the rest of filename.)
#error "Currently filename re-encoding is done in-place. It may break the remaining chars to use 3-byte codepoints."
#endif
@@ -1517,7 +1516,7 @@ int8_t SdBaseFile::readDir(dir_t *dir, char *longFilename) {
if (longFilename) {
// Reset n to the start of the long name
n = 0;
for (uint16_t idx = 0; idx < (LONG_FILENAME_LENGTH) / 2; idx += 2) { // idx is fixed since FAT LFN always contains UTF-16LE encoding
for (uint16_t idx = 0; idx < (LONG_FILENAME_LENGTH); idx += 2) { // idx is fixed since FAT LFN always contains UTF-16LE encoding
const uint16_t utf16_ch = longFilename[idx] | (longFilename[idx + 1] << 8);
if (0xD800 == (utf16_ch & 0xF800)) // Surrogate pair - encode as '_'
longFilename[n++] = '_';