aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-08-16 00:06:18 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-08-16 00:06:18 +0000
commitb49c879015d03081c3a515bca25681ca3d50cead (patch)
tree9ad0bded599da93b2b375517f22dfcdf9c63b188 /src
parentf0f46ed66a177e5349a6d84e8fff91e6aa6b0dac (diff)
downloadpostgresql-b49c879015d03081c3a515bca25681ca3d50cead.tar.gz
postgresql-b49c879015d03081c3a515bca25681ca3d50cead.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/mbprint.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/src/bin/psql/mbprint.c b/src/bin/psql/mbprint.c
index b1263ea5918..d46aaef544f 100644
--- a/src/bin/psql/mbprint.c
+++ b/src/bin/psql/mbprint.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.38 2010/01/02 16:57:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.39 2010/08/16 00:06:18 tgl Exp $
*
* XXX this file does not really belong in psql/. Perhaps move to libpq?
* It also seems that the mbvalidate function is redundant with existing
@@ -53,28 +53,20 @@ utf2ucs(const unsigned char *c)
if ((*c & 0x80) == 0)
return (pg_wchar) c[0];
else if ((*c & 0xe0) == 0xc0)
- {
return (pg_wchar) (((c[0] & 0x1f) << 6) |
(c[1] & 0x3f));
- }
else if ((*c & 0xf0) == 0xe0)
- {
return (pg_wchar) (((c[0] & 0x0f) << 12) |
((c[1] & 0x3f) << 6) |
(c[2] & 0x3f));
- }
- else if ((*c & 0xf0) == 0xf0)
- {
+ else if ((*c & 0xf8) == 0xf0)
return (pg_wchar) (((c[0] & 0x07) << 18) |
((c[1] & 0x3f) << 12) |
((c[2] & 0x3f) << 6) |
(c[3] & 0x3f));
- }
else
- {
/* that is an invalid code on purpose */
return 0xffffffff;
- }
}