diff options
author | Marek Vasut <marex@denx.de> | 2025-03-17 04:12:47 +0100 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-04-02 20:00:59 -0600 |
commit | 74eb84686f9600d5aeed001f913c1e8c91b1a4ca (patch) | |
tree | 8a34cdfbae403c824bd3dba8847e00e71872940d | |
parent | b86a651b646c0c676ab2746344edb2d7e5d81e98 (diff) |
fs: exfat: Fix conversion overflow errors
Fix the following conversion overflow errors. The UTF8-to-UTF16
conversion is done through 32bit wchar_t, but U-Boot codebase is
built with -fshort-wchar which limits wchar_t to 16bit. Replace
the built-in wchar_t with u32 to assure the intermediate type is
32bit.
"
fs/exfat/utf.c: In function ‘utf8_to_wchar’:
fs/exfat/utf.c:165:23: warning: overflow in conversion from ‘int’ to ‘wchar_t’ {aka ‘short unsigned int’} changes value from ‘(int)(short unsigned int)*input << 18 & 1835008’ to ‘0’ [-Woverflow]
165 | *wc = ((wchar_t) input[0] & 0x07) << 18;
| ^
fs/exfat/utf.c:170:23: warning: overflow in conversion from ‘int’ to ‘wchar_t’ {aka ‘short unsigned int’} changes value from ‘(int)(short unsigned int)*input << 24 & 50331648’ to ‘0’ [-Woverflow]
170 | *wc = ((wchar_t) input[0] & 0x03) << 24;
| ^
fs/exfat/utf.c:175:23: warning: overflow in conversion from ‘int’ to ‘wchar_t’ {aka ‘short unsigned int’} changes value from ‘(int)(short unsigned int)*input << 30 & 1073741824’ to ‘0’ [-Woverflow]
175 | *wc = ((wchar_t) input[0] & 0x01) << 30;
| ^
"
Signed-off-by: Marek Vasut <marex@denx.de>
-rw-r--r-- | fs/exfat/utf.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/fs/exfat/utf.c b/fs/exfat/utf.c index b1d09e76478..8a28e7621ca 100644 --- a/fs/exfat/utf.c +++ b/fs/exfat/utf.c @@ -23,7 +23,7 @@ #include "exfat.h" #include <errno.h> -static char* wchar_to_utf8(char* output, wchar_t wc, size_t outsize) +static char* wchar_to_utf8(char* output, u32 wc, size_t outsize) { if (wc <= 0x7f) { @@ -82,14 +82,14 @@ static char* wchar_to_utf8(char* output, wchar_t wc, size_t outsize) return output; } -static const le16_t* utf16_to_wchar(const le16_t* input, wchar_t* wc, +static const le16_t* utf16_to_wchar(const le16_t* input, u32* wc, size_t insize) { if ((le16_to_cpu(input[0]) & 0xfc00) == 0xd800) { if (insize < 2 || (le16_to_cpu(input[1]) & 0xfc00) != 0xdc00) return NULL; - *wc = ((wchar_t) (le16_to_cpu(input[0]) & 0x3ff) << 10); + *wc = ((u32) (le16_to_cpu(input[0]) & 0x3ff) << 10); *wc |= (le16_to_cpu(input[1]) & 0x3ff); *wc += 0x10000; return input + 2; @@ -108,7 +108,7 @@ int exfat_utf16_to_utf8(char* output, const le16_t* input, size_t outsize, const le16_t* iend = input + insize; char* optr = output; const char* oend = output + outsize; - wchar_t wc; + u32 wc; while (iptr < iend) { @@ -136,7 +136,7 @@ int exfat_utf16_to_utf8(char* output, const le16_t* input, size_t outsize, return 0; } -static const char* utf8_to_wchar(const char* input, wchar_t* wc, +static const char* utf8_to_wchar(const char* input, u32* wc, size_t insize) { size_t size; @@ -147,32 +147,32 @@ static const char* utf8_to_wchar(const char* input, wchar_t* wc, if ((input[0] & 0x80) == 0) { - *wc = (wchar_t) input[0]; + *wc = (u32) input[0]; return input + 1; } else if ((input[0] & 0xe0) == 0xc0) { - *wc = ((wchar_t) input[0] & 0x1f) << 6; + *wc = ((u32) input[0] & 0x1f) << 6; size = 2; } else if ((input[0] & 0xf0) == 0xe0) { - *wc = ((wchar_t) input[0] & 0x0f) << 12; + *wc = ((u32) input[0] & 0x0f) << 12; size = 3; } else if ((input[0] & 0xf8) == 0xf0) { - *wc = ((wchar_t) input[0] & 0x07) << 18; + *wc = ((u32) input[0] & 0x07) << 18; size = 4; } else if ((input[0] & 0xfc) == 0xf8) { - *wc = ((wchar_t) input[0] & 0x03) << 24; + *wc = ((u32) input[0] & 0x03) << 24; size = 5; } else if ((input[0] & 0xfe) == 0xfc) { - *wc = ((wchar_t) input[0] & 0x01) << 30; + *wc = ((u32) input[0] & 0x01) << 30; size = 6; } else @@ -192,7 +192,7 @@ static const char* utf8_to_wchar(const char* input, wchar_t* wc, return input + size; } -static le16_t* wchar_to_utf16(le16_t* output, wchar_t wc, size_t outsize) +static le16_t* wchar_to_utf16(le16_t* output, u32 wc, size_t outsize) { if (wc <= 0xffff) /* if character is from BMP */ { @@ -216,7 +216,7 @@ int exfat_utf8_to_utf16(le16_t* output, const char* input, size_t outsize, const char* iend = input + insize; le16_t* optr = output; const le16_t* oend = output + outsize; - wchar_t wc; + u32 wc; while (iptr < iend) { |