10000 Fix psql's copy of utf2ucs() to match the backend's copy exactly; · danielcode/postgres@4d1dd8d · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d1dd8d

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 019e2f4 commit 4d1dd8d

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-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.16 2005/01/01 05:43:08 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.16.4.1 2010/08/16 00:06:54 tgl Exp $
77
*/
88

99
#include "postgres_fe.h"
@@ -168,28 +168,20 @@ utf2ucs(const unsigned char *c)
168168
if ((*c & 0x80) == 0)
169169
return (pg_wchar) c[0];
170170
else if ((*c & 0xe0) == 0xc0)
171-
{
172171
return (pg_wchar) (((c[0] & 0x1f) << 6) |
173172
(c[1] & 0x3f));
174-
}
175173
else if ((*c & 0xf0) == 0xe0)
176-
{
177174
return (pg_wchar) (((c[0] & 0x0f) << 12) |
178175
((c[1] & 0x3f) << 6) |
179176
(c[2] & 0x3f));
180-
}
181-
else if ((*c & 0xf0) == 0xf0)
182-
{
177+
else if ((*c & 0xf8) == 0xf0)
183178
return (pg_wchar) (((c[0] & 0x07) << 18) |
184179
((c[1] & 0x3f) << 12) |
185180
((c[2] & 0x3f) << 6) |
186181
(c[3] & 0x3f));
187-
}
188182
else
189-
{
190183
/* that is an invalid code on purpose */
191184
return 0xffffffff;
192-
}
193185
}
194186

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

0 commit comments

Comments
 (0)
0