Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gIzKb-0004a8-JD for pgsql-bugs@arkaria.postgresql.org; Sat, 03 Nov 2018 17:03:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gIzKY-00034K-Pq for pgsql-bugs@arkaria.postgresql.org; Sat, 03 Nov 2018 17:03:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gIzKY-00034C-G6 for pgsql-bugs@lists.postgresql.org; Sat, 03 Nov 2018 17:03:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gIzKV-0002jW-VT for pgsql-bugs@lists.postgresql.org; Sat, 03 Nov 2018 17:03:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wA3H3KBO003874; Sat, 3 Nov 2018 13:03:20 -0400 From: Tom Lane To: kenji uno cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15476: Problem on show_trgm with 4 byte UTF-8 characters In-reply-to: References: <15476-4314f480acf0f114@postgresql.org> <2101.1541220270@sss.pgh.pa.us> Comments: In-reply-to kenji uno message dated "Sat, 03 Nov 2018 23:30:16 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3872.1541264600.1@sss.pgh.pa.us> Date: Sat, 03 Nov 2018 13:03:20 -0400 Message-ID: <3873.1541264600@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk kenji uno writes: >> I failed to reproduce this on a Linux machine. It looks to me like the >> problem is that Windows' MultiByteToWideChar doesn't think that UTF8 >> character is valid. > I'm just wondering why my issue occurs only on Windows. > But I knew why: char2wchar's tolen requires +1 output buffer size, due to > null-termination. Oooh ... the problem, effectively, is that the ts_locale.c functions are expecting to get back UTF32 but what they'll actually get on Windows is UTF16. So if the given character is outside the BMP range, char2wchar needs to produce a surrogate pair, which there's not room for given that the output buffer can only hold 1 wchar_t plus trailing null. Then the other problem is that the Windows-Unicode code path in char2wchar just fails for an undersized output buffer, which you would not expect from its documentation. And it fails with a misleading error message, too. I'll see what I can do about this --- thanks for the report! regards, tom lane