-- v2: mfplat: Use the isxdigit function instead of reimplementing it.
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/mfplat/main.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/dlls/mfplat/main.c b/dlls/mfplat/main.c index ebab4ed6f1f..ad98d7e2691 100644 --- a/dlls/mfplat/main.c +++ b/dlls/mfplat/main.c @@ -646,15 +646,6 @@ static WCHAR* guid_to_string(WCHAR *str, REFGUID guid) return str; }
-static inline BOOL is_valid_hex(WCHAR c) -{ - if (!(((c >= '0') && (c <= '9')) || - ((c >= 'a') && (c <= 'f')) || - ((c >= 'A') && (c <= 'F')))) - return FALSE; - return TRUE; -} - static BOOL GUIDFromString(LPCWSTR s, GUID *id) { int i; @@ -664,7 +655,7 @@ static BOOL GUIDFromString(LPCWSTR s, GUID *id) id->Data1 = 0; for (i = 0; i < 8; i++) { - if (!is_valid_hex(s[i])) return FALSE; + if (!isxdigit(s[i])) return FALSE; id->Data1 = (id->Data1 << 4) | guid_conv_table[s[i]]; } if (s[8]!='-') return FALSE; @@ -672,7 +663,7 @@ static BOOL GUIDFromString(LPCWSTR s, GUID *id) id->Data2 = 0; for (i = 9; i < 13; i++) { - if (!is_valid_hex(s[i])) return FALSE; + if (!isxdigit(s[i])) return FALSE; id->Data2 = (id->Data2 << 4) | guid_conv_table[s[i]]; } if (s[13]!='-') return FALSE; @@ -680,7 +671,7 @@ static BOOL GUIDFromString(LPCWSTR s, GUID *id) id->Data3 = 0; for (i = 14; i < 18; i++) { - if (!is_valid_hex(s[i])) return FALSE; + if (!isxdigit(s[i])) return FALSE; id->Data3 = (id->Data3 << 4) | guid_conv_table[s[i]]; } if (s[18]!='-') return FALSE; @@ -692,7 +683,7 @@ static BOOL GUIDFromString(LPCWSTR s, GUID *id) if (s[i]!='-') return FALSE; i++; } - if (!is_valid_hex(s[i]) || !is_valid_hex(s[i+1])) return FALSE; + if (!isxdigit(s[i]) || !isxdigit(s[i+1])) return FALSE; id->Data4[(i-19)/2] = guid_conv_table[s[i]] << 4 | guid_conv_table[s[i+1]]; }
On Wed Nov 23 06:43:09 2022 +0000, Alex Henrie wrote:
My mistake. It looks like the equivalent function is `isxdigit`, without the "w". Despite the lack of a "w" it does operate on Unicode characters.
Looks like it's still doing too much, handling multibyte codepages.
On Wed Nov 23 07:05:07 2022 +0000, Nikolay Sivov wrote:
Looks like it's still doing too much, handling multibyte codepages.
Oh, weird. I wrote a small test program and you're right, on Windows isxdigit can be true for characters above 255:
``` #include <locale.h> #include <stdio.h> #include <ctype.h>
int main() { if (!setlocale(LC_ALL, "chinese")) printf("setlocale failed\n");
if (isxdigit(0x6161)) printf("0x6161 is a hex digit\n"); else printf("0x6161 is NOT a hex digit\n");
return 0; } ```
On Windows, the program prints "0x6161 is a hex digit". However, on Linux, the same program with "chinese" changed to "zh-CN" prints "0x6161 is NOT a hex digit". I checked the C99 standard and it says:
The header <ctype.h> declares several functions useful for classifying and mapping characters.) In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.
So it seems that Windows is well within its rights to do whatever it wants if c > 255.
This merge request was closed by Alex Henrie.