8000 Fix psql's copy of utf2ucs() to match the backend's copy exactly; · home201448/postgres@9217dee · GitHub
[go: up one dir, main page]

Skip to content

Commit 9217dee

Browse files
committed
Fix psql's copy of utf2ucs() to match the backend's copy exactly;
in particular, propagate a fix in the test to see whether a UTF8 character has length 4 bytes. This is likely of little real-world consequence because 5-or-more-byte UTF8 sequences are not supported by Postgres nor seen anywhere in the wild, but still we may as well get it right. Problem found by Joseph Adams. Bug is aboriginal, so back-patch all the way.
1 parent 1207827 commit 9217dee

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/bin/psql/mbprint.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.12 2003/09/12 02:40:09 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.12.2.1 2010/08/16 00:07:00 tgl Exp $
77
*/
88

99
#include "postgres_fe.h"
@@ -172,28 +172,20 @@ utf2ucs(const unsigned char *c)
172172
if ((*c & 0x80) == 0)
173173
return (pg_wchar) c[0];
174174
else if ((*c & 0xe0) == 0xc0)
175-
{
176175
return (pg_wchar) (((c[0] & 0x1f) << 6) |
177176
(c[1] & 0x3f));
178-
}
179177
else if ((*c & 0xf0) == 0xe0)
180-
{
181178
return (pg_wchar) (((c[0] & 0x0f) << 12) |
182179
((c[1] & 0x3f) << 6) |
183180
(c[2] & 0x3f));
184-
}
185-
else if ((*c & 0xf0) == 0xf0)
186-
{
181+
else if ((*c & 0xf8) == 0xf0)
187182
return (pg_wchar) (((c[0] & 0x07) << 18) |
188183
((c[1] & 0x3f) << 12) |
189184
((c[2] & 0x3f) << 6) |
190185
(c[3] & 0x3f));
191-
}
192186
else
193-
{
194187
/* that is an invalid code on purpose */
195188
return 0xffffffff;
196-
}
197189
}
198190

199191
/* mb_utf_wcwidth : calculate column length for the utf8 string pwcs

0 commit comments

Comments
 (0)
0