pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Unicode normalization test broken output
Date: Tue, 10 Dec 2019 13:18:31 +0100
Message-ID: <f8da0a2d-bca3-0c6a-e6be-499c6e53fb3e@2ndquadrant.com> (raw)
In-Reply-To: <16791.1575930159@sss.pgh.pa.us>
References: <6a7a8516-7d11-8fbd-0e8b-eadb4f0679eb@2ndquadrant.com>
	<16791.1575930159@sss.pgh.pa.us>

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

view thread (5+ messages)  latest in thread

Message-ID: <f8da0a2d-bca3-0c6a-e6be-499c6e53fb3e@2ndquadrant.com>
Permalink:  ../f8da0a2d-bca3-0c6a-e6be-499c6e53fb3e@2ndquadrant.com/
Also on:    postgresql.org/message-id/f8da0a2d-bca3-0c6a-e6be-499c6e53fb3e@2ndquadrant.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: peter.eisentraut@2ndquadrant.com, tgl@sss.pgh.pa.us
  Subject: Re: Unicode normalization test broken output
  In-Reply-To: <f8da0a2d-bca3-0c6a-e6be-499c6e53fb3e@2ndquadrant.com>
  References: <6a7a8516-7d11-8fbd-0e8b-eadb4f0679eb@2ndquadrant.com> <16791.1575930159@sss.pgh.pa.us> <f8da0a2d-bca3-0c6a-e6be-499c6e53fb3e@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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