diff --git a/dlls/atl/registrar.c b/dlls/atl/registrar.c index 612274d1a92..586cce3201d 100644 --- a/dlls/atl/registrar.c +++ b/dlls/atl/registrar.c @@ -99,6 +99,14 @@ static void strbuf_write(LPCOLESTR str, strbuf *buf, int len) buf->str[buf->len] = '\0'; } +static int xdigit_to_int(WCHAR c) +{ + if('0' <= c && c <= '9') return c - '0'; + if('a' <= c && c <= 'f') return c - 'a' + 10; + if('A' <= c && c <= 'F') return c - 'A' + 10; + return -1; +} + static HRESULT get_word(LPCOLESTR *str, strbuf *buf) { LPCOLESTR iter, iter2 = *str; @@ -303,15 +311,12 @@ static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOO break; } for(i = 0; i < count && buf->str[2*i]; i++) { - WCHAR digits[3]; - if(!iswxdigit(buf->str[2*i]) || !iswxdigit(buf->str[2*i + 1])) { + int d1, d2; + if((d1 = xdigit_to_int(buf->str[2*i])) == -1 || (d2 = xdigit_to_int(buf->str[2*i + 1])) == -1) { hres = E_FAIL; break; } - digits[0] = buf->str[2*i]; - digits[1] = buf->str[2*i + 1]; - digits[2] = 0; - bytes[i] = (BYTE) wcstoul(digits, NULL, 16); + bytes[i] = (d1 << 4) | d2; } if(SUCCEEDED(hres)) { lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_BINARY, diff --git a/dlls/atl/tests/registrar.c b/dlls/atl/tests/registrar.c index 4ecb092fd65..f9ec9529dd8 100644 --- a/dlls/atl/tests/registrar.c +++ b/dlls/atl/tests/registrar.c @@ -48,7 +48,7 @@ static const char textA[] = " val 'dword_quoted_hex' = d '0xA' \n" " val 'dword_unquoted_hex' = d 0xA \n" " val 'binary_quoted' = b 'deadbeef' \n" -" val 'binary_unquoted' = b deadbeef \n" +" val 'binary_unquoted' = b dead0123 \n" " } \n" "}"; @@ -124,7 +124,7 @@ static void test_registrar(void) size = 4; lret = RegQueryValueExA(key, "binary_unquoted", NULL, NULL, bytes, &size); ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret); - ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef, + ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0x01 && bytes[3] == 0x23, "binary unquoted value was not preserved (it's 0x%02X%02X%02X%02X)\n", 0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);