Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- dlls/kernel32/tests/locale.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c index fa0ec374d34..4fb30eb5318 100644 --- a/dlls/kernel32/tests/locale.c +++ b/dlls/kernel32/tests/locale.c @@ -3962,6 +3962,7 @@ static void test_GetCPInfo(void) ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
+ memset(cpinfo.LeadByte, '-', ARRAY_SIZE(cpinfo.LeadByte)); SetLastError(0xdeadbeef); ret = GetCPInfo(CP_UTF7, &cpinfo); if (!ret && GetLastError() == ERROR_INVALID_PARAMETER) @@ -3970,14 +3971,19 @@ static void test_GetCPInfo(void) } else { + unsigned int i; + ok(ret, "GetCPInfo(CP_UTF7) error %u\n", GetLastError()); ok(cpinfo.DefaultChar[0] == 0x3f, "expected 0x3f, got 0x%x\n", cpinfo.DefaultChar[0]); ok(cpinfo.DefaultChar[1] == 0, "expected 0, got 0x%x\n", cpinfo.DefaultChar[1]); ok(cpinfo.LeadByte[0] == 0, "expected 0, got 0x%x\n", cpinfo.LeadByte[0]); ok(cpinfo.LeadByte[1] == 0, "expected 0, got 0x%x\n", cpinfo.LeadByte[1]); + for (i = 2; i < sizeof(cpinfo.LeadByte); i++) + todo_wine ok(!cpinfo.LeadByte[i], "expected NUL byte in index %u\n", i); ok(cpinfo.MaxCharSize == 5, "expected 5, got 0x%x\n", cpinfo.MaxCharSize); }
+ memset(cpinfo.LeadByte, '-', ARRAY_SIZE(cpinfo.LeadByte)); SetLastError(0xdeadbeef); ret = GetCPInfo(CP_UTF8, &cpinfo); if (!ret && GetLastError() == ERROR_INVALID_PARAMETER) @@ -3986,11 +3992,15 @@ static void test_GetCPInfo(void) } else { + unsigned int i; + ok(ret, "GetCPInfo(CP_UTF8) error %u\n", GetLastError()); ok(cpinfo.DefaultChar[0] == 0x3f, "expected 0x3f, got 0x%x\n", cpinfo.DefaultChar[0]); ok(cpinfo.DefaultChar[1] == 0, "expected 0, got 0x%x\n", cpinfo.DefaultChar[1]); ok(cpinfo.LeadByte[0] == 0, "expected 0, got 0x%x\n", cpinfo.LeadByte[0]); ok(cpinfo.LeadByte[1] == 0, "expected 0, got 0x%x\n", cpinfo.LeadByte[1]); + for (i = 2; i < sizeof(cpinfo.LeadByte); i++) + todo_wine ok(!cpinfo.LeadByte[i], "expected NUL byte in index %u\n", i); ok(cpinfo.MaxCharSize == 4 || broken(cpinfo.MaxCharSize == 3) /* win9x */, "expected 4, got %u\n", cpinfo.MaxCharSize); }
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- dlls/kernel32/tests/locale.c | 12 ++++-------- dlls/kernelbase/locale.c | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c index 4fb30eb5318..cad2577379b 100644 --- a/dlls/kernel32/tests/locale.c +++ b/dlls/kernel32/tests/locale.c @@ -3976,10 +3976,8 @@ static void test_GetCPInfo(void) ok(ret, "GetCPInfo(CP_UTF7) error %u\n", GetLastError()); ok(cpinfo.DefaultChar[0] == 0x3f, "expected 0x3f, got 0x%x\n", cpinfo.DefaultChar[0]); ok(cpinfo.DefaultChar[1] == 0, "expected 0, got 0x%x\n", cpinfo.DefaultChar[1]); - ok(cpinfo.LeadByte[0] == 0, "expected 0, got 0x%x\n", cpinfo.LeadByte[0]); - ok(cpinfo.LeadByte[1] == 0, "expected 0, got 0x%x\n", cpinfo.LeadByte[1]); - for (i = 2; i < sizeof(cpinfo.LeadByte); i++) - todo_wine ok(!cpinfo.LeadByte[i], "expected NUL byte in index %u\n", i); + for (i = 0; i < sizeof(cpinfo.LeadByte); i++) + ok(!cpinfo.LeadByte[i], "expected NUL byte in index %u\n", i); ok(cpinfo.MaxCharSize == 5, "expected 5, got 0x%x\n", cpinfo.MaxCharSize); }
@@ -3997,10 +3995,8 @@ static void test_GetCPInfo(void) ok(ret, "GetCPInfo(CP_UTF8) error %u\n", GetLastError()); ok(cpinfo.DefaultChar[0] == 0x3f, "expected 0x3f, got 0x%x\n", cpinfo.DefaultChar[0]); ok(cpinfo.DefaultChar[1] == 0, "expected 0, got 0x%x\n", cpinfo.DefaultChar[1]); - ok(cpinfo.LeadByte[0] == 0, "expected 0, got 0x%x\n", cpinfo.LeadByte[0]); - ok(cpinfo.LeadByte[1] == 0, "expected 0, got 0x%x\n", cpinfo.LeadByte[1]); - for (i = 2; i < sizeof(cpinfo.LeadByte); i++) - todo_wine ok(!cpinfo.LeadByte[i], "expected NUL byte in index %u\n", i); + for (i = 0; i < sizeof(cpinfo.LeadByte); i++) + ok(!cpinfo.LeadByte[i], "expected NUL byte in index %u\n", i); ok(cpinfo.MaxCharSize == 4 || broken(cpinfo.MaxCharSize == 3) /* win9x */, "expected 4, got %u\n", cpinfo.MaxCharSize); } diff --git a/dlls/kernelbase/locale.c b/dlls/kernelbase/locale.c index 259b9d0d18e..10f3b2698b5 100644 --- a/dlls/kernelbase/locale.c +++ b/dlls/kernelbase/locale.c @@ -3905,7 +3905,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetCPInfo( UINT codepage, CPINFO *cpinfo ) case CP_UTF8: cpinfo->DefaultChar[0] = 0x3f; cpinfo->DefaultChar[1] = 0; - cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0; + memset( cpinfo->LeadByte, 0, sizeof(cpinfo->LeadByte) ); cpinfo->MaxCharSize = (codepage == CP_UTF7) ? 5 : 4; break; default:
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/conhost/window.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/programs/conhost/window.c b/programs/conhost/window.c index 319463537d5..eab98c11d54 100644 --- a/programs/conhost/window.c +++ b/programs/conhost/window.c @@ -627,6 +627,7 @@ static HFONT select_font_config( struct console_config *config, unsigned int cp, TEXTMETRICW tm; CPINFO cpinfo; HDC dc; + static const BYTE lead_bytes[MAX_LEADBYTES] = { 0 };
if (!(dc = GetDC( hwnd ))) return NULL; if (!(font = CreateFontIndirectW( lf ))) @@ -646,7 +647,8 @@ static HFONT select_font_config( struct console_config *config, unsigned int cp, lstrcpyW( config->face_name, lf->lfFaceName );
/* FIXME: use maximum width for DBCS codepages since some chars take two cells */ - if (GetCPInfo( cp, &cpinfo ) && cpinfo.MaxCharSize > 1) + GetCPInfo( cp, &cpinfo ); + if (memcmp( cpinfo.LeadByte, lead_bytes, sizeof(cpinfo.LeadByte) )) config->cell_width = tm.tmMaxCharWidth;
return font;
Hugh McMaster hugh.mcmaster@outlook.com writes:
@@ -646,7 +647,8 @@ static HFONT select_font_config( struct console_config *config, unsigned int cp, lstrcpyW( config->face_name, lf->lfFaceName );
/* FIXME: use maximum width for DBCS codepages since some chars take two cells */
- if (GetCPInfo( cp, &cpinfo ) && cpinfo.MaxCharSize > 1)
- GetCPInfo( cp, &cpinfo );
- if (memcmp( cpinfo.LeadByte, lead_bytes, sizeof(cpinfo.LeadByte) )) config->cell_width = tm.tmMaxCharWidth;
That seems like a roundabout way of doing it. Wouldn't cpinfo.MaxCharSize == 2 work as well?
On Tue, 23 Nov 2021 at 07:41, Alexandre Julliard wrote:
Hugh McMaster writes:
@@ -646,7 +647,8 @@ static HFONT select_font_config( struct console_config *config, unsigned int cp, lstrcpyW( config->face_name, lf->lfFaceName );
/* FIXME: use maximum width for DBCS codepages since some chars take two cells */
- if (GetCPInfo( cp, &cpinfo ) && cpinfo.MaxCharSize > 1)
- GetCPInfo( cp, &cpinfo );
- if (memcmp( cpinfo.LeadByte, lead_bytes, sizeof(cpinfo.LeadByte) )) config->cell_width = tm.tmMaxCharWidth;
That seems like a roundabout way of doing it. Wouldn't cpinfo.MaxCharSize == 2 work as well?
Yes, it would. The docs warn against relying on MaxCharSize, but I don't see any reason that would affect this usage.
"The function cannot use the size to distinguish an SBCS or a DBCS from other character sets because of other factors, for example, the use of ISCII or ISO-2022-xx code pages." [1]
[1] https://docs.microsoft.com/en-us/windows/win32/api/winnls/ns-winnls-cpinfo