pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Unicode normalization test broken output
5+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2019-12-11 b802412106  Fix output of Unicode normalization test
* Unicode normalization test broken output
@ 2019-12-09 11:05  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Peter Eisentraut @ 2019-12-09 11:05 UTC (permalink / raw)
  To: pgsql-hackers

I was playing with the Unicode normalization test in 
src/common/unicode/.  I think there is something wrong with how the test 
program reports failures.  For example, if I manually edit the 
norm_test_table.h to make a failure, like

-    { 74, { 0x00A8, 0 }, { 0x0020, 0x0308, 0 } },
+    { 74, { 0x00A8, 0 }, { 0x0020, 0x0309, 0 } },

then the output from the test is

FAILURE (NormalizationTest.txt line 74):
input:	00
expected:	0003
got	0003

which doesn't make sense.

There appear to be several off-by-more-than-one errors in norm_test.c 
print_wchar_str().  Attached is a patch to fix this (and make the output 
a bit prettier).  Result afterwards:

FAILURE (NormalizationTest.txt line 74):
input:    U+00A8
expected: U+0020 U+0309
got:      U+0020 U+0308

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Fix-output-of-Unicode-normalization-test.patch (text/plain, 1.5K) download From b9dce0b6185ce8a05780d64a5a284b3eb7c7e7ea Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Mon, 9 Dec 2019 12:02:49 +0100 Subject: [PATCH] Fix output of Unicode normalization test Several off-by-more-than-one errors caused the output in case of a test failure to be unintelligible. --- src/common/unicode/norm_test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/unicode/norm_test.c b/src/common/unicode/norm_test.c index fee58a184a..b6d34dd22c 100644 --- a/src/common/unicode/norm_test.c +++ b/src/common/unicode/norm_test.c @@ -23,17 +23,17 @@ static char * print_wchar_str(const pg_wchar *s) { #define BUF_DIGITS 50 - static char buf[BUF_DIGITS * 2 + 1]; + static char buf[BUF_DIGITS * 7 + 1]; int i; i = 0; while (*s && i < BUF_DIGITS) { - snprintf(&buf[i * 2], 3, "%04X", *s); + sprintf(&buf[i * 7], "U+%04X ", *s); i++; s++; } - buf[i * 2] = '\0'; + buf[i * 7] = '\0'; return buf; } @@ -67,9 +67,9 @@ main(int argc, char **argv) if (pg_wcscmp(test->output, result) != 0) { printf("FAILURE (NormalizationTest.txt line %d):\n", test->linenum); - printf("input:\t%s\n", print_wchar_str(test->input)); - printf("expected:\t%s\n", print_wchar_str(test->output)); - printf("got\t%s\n", print_wchar_str(result)); + printf("input: %s\n", print_wchar_str(test->input)); + printf("expected: %s\n", print_wchar_str(test->output)); + printf("got: %s\n", print_wchar_str(result)); printf("\n"); exit(1); } -- 2.24.0
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: Unicode normalization test broken output
@ 2019-12-09 22:22  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2019-12-09 22:22 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-hackers

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> There appear to be several off-by-more-than-one errors in norm_test.c 
> print_wchar_str().  Attached is a patch to fix this (and make the output 
> a bit prettier).  Result afterwards:

I concur that this looks broken and your patch improves it.
But I'm not very happy about the remaining assumption that
we don't have to worry about characters above U+FFFF.  I'd
rather see it allocate 11 bytes per allowed pg_wchar, and
manage the string contents with something like

	p += sprintf(p, "U+%04X ", *s);

An alternative fix would be to start using a PQExpBuffer, but
it's probably not quite worth that.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Unicode normalization test broken output
@ 2019-12-10 12:18  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Peter Eisentraut @ 2019-12-10 12:18 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers

On 2019-12-09 23:22, Tom Lane wrote:
> Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
>> There appear to be several off-by-more-than-one errors in norm_test.c
>> print_wchar_str().  Attached is a patch to fix this (and make the output
>> a bit prettier).  Result afterwards:
> 
> I concur that this looks broken and your patch improves it.
> But I'm not very happy about the remaining assumption that
> we don't have to worry about characters above U+FFFF.  I'd
> rather see it allocate 11 bytes per allowed pg_wchar, and
> manage the string contents with something like
> 
> 	p += sprintf(p, "U+%04X ", *s);

Good point.  Fixed in attached patch.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Fix-output-of-Unicode-normalization-test.patch (text/plain, 1.7K) download From bece2b343999f1545f1ff2b5be060d7a0e22a91a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Tue, 10 Dec 2019 13:17:20 +0100 Subject: [PATCH v2] Fix output of Unicode normalization test Several off-by-more-than-one errors caused the output in case of a test failure to be unintelligible. Discussion: https://www.postgresql.org/message-id/flat/6a7a8516-7d11-8fbd-0e8b-eadb4f0679eb%402ndquadrant.com --- src/common/unicode/norm_test.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common/unicode/norm_test.c b/src/common/unicode/norm_test.c index fee58a184a..de7d6a72c7 100644 --- a/src/common/unicode/norm_test.c +++ b/src/common/unicode/norm_test.c @@ -23,17 +23,20 @@ static char * print_wchar_str(const pg_wchar *s) { #define BUF_DIGITS 50 - static char buf[BUF_DIGITS * 2 + 1]; + static char buf[BUF_DIGITS * 11 + 1]; int i; + char *p; i = 0; + p = buf; while (*s && i < BUF_DIGITS) { - snprintf(&buf[i * 2], 3, "%04X", *s); + p += sprintf(p, "U+%04X ", *s); i++; s++; } - buf[i * 2] = '\0'; + *p = '\0'; + return buf; } @@ -67,9 +70,9 @@ main(int argc, char **argv) if (pg_wcscmp(test->output, result) != 0) { printf("FAILURE (NormalizationTest.txt line %d):\n", test->linenum); - printf("input:\t%s\n", print_wchar_str(test->input)); - printf("expected:\t%s\n", print_wchar_str(test->output)); - printf("got\t%s\n", print_wchar_str(result)); + printf("input: %s\n", print_wchar_str(test->input)); + printf("expected: %s\n", print_wchar_str(test->output)); + printf("got: %s\n", print_wchar_str(result)); printf("\n"); exit(1); } -- 2.24.0
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: Unicode normalization test broken output
@ 2019-12-10 16:16  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2019-12-10 16:16 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-hackers

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> Good point.  Fixed in attached patch.

This one LGTM.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Unicode normalization test broken output
@ 2019-12-11 07:45  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Peter Eisentraut @ 2019-12-11 07:45 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers

On 2019-12-10 17:16, Tom Lane wrote:
> Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
>> Good point.  Fixed in attached patch.
> 
> This one LGTM.

done, thanks

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-12-11 07:45 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09 11:05 Unicode normalization test broken output Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-12-09 22:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-12-10 12:18   ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-12-10 16:16     ` Tom Lane <tgl@sss.pgh.pa.us>
2019-12-11 07:45       ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox