summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-08-16 00:07:00 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-08-16 00:07:00 +0000
commit9217dee11811b37495766c58e4f67c9b3461c962 (patch)
tree47e5fd4e2118f81650fa932a80b119ca1ad08122
parent120782773d7e9e80a2e77f2fee5cf7a016e017d8 (diff)
downloadpostgresql-9217dee11811b37495766c58e4f67c9b3461c962.tar.gz
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.
-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 f8560f8166..d2667d6da7 100644
--- a/src/bin/psql/mbprint.c
+++ b/src/bin/psql/mbprint.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.12 2003/09/12 02:40:09 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.12.2.1 2010/08/16 00:07:00 tgl Exp $
*/
#include "postgres_fe.h"
@@ -172,28 +172,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;
- }
}
/* mb_utf_wcwidth : calculate column length for the utf8 string pwcs