From d59c7c8b35fedc2b247afee56d91c2a44101253d Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Sun, 19 Jun 2016 19:48:48 +0000 Subject: [PATCH] More correctly handle the case where plain char is signed In _FAT_directory_lfnLength, the check 'ch < 0x20' incorrectly catches any extended UTF-8 bytes if the plain 'char' type is signed: 0x80 < 0x20 ... 0xEF < 0x20 are interpreted as (negative value < 32). The check for 0xF0 and above also fails to work properly due to 0xF0 being negative as well. --- source/directory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/directory.c b/source/directory.c index ff849e2..18641f9 100644 --- a/source/directory.c +++ b/source/directory.c @@ -98,7 +98,8 @@ static int _FAT_directory_lfnLength (const char* name) { } // Make sure the name doesn't contain any control codes or codes not representable in UCS-2 for (i = 0; i < nameLength; i++) { - if (name[i] < 0x20 || name[i] >= ABOVE_UCS_RANGE) { + unsigned char ch = (unsigned char) name[i]; + if (ch < 0x20 || ch >= ABOVE_UCS_RANGE) { return -1; } }