Peter Eisentraut <pete...@gmx.net> writes: > On ons, 2012-02-22 at 22:37 +0400, Sergey Burladyan wrote: > > eshkin...@gmail.com writes: > > > > > The following bug has been logged on the website: > > > > > > Bug reference: 6480 > > > Logged by: Sergey Burladyan > > > Email address: eshkin...@gmail.com > > > PostgreSQL version: 9.1.2 > > > Operating system: Debian testing > > > Description: > > > > > > This code incorrectly calculate width for translated text if it multibyte > > > string. strlen(ct) vs. UTF-8 > > > > > > src/bin/psql/describe.c:2100 > > Can you prepare a patch? >
Surely, I was sent this patch to pgsql-hackers and added to the commitfest-next to be sure I'll never lost it https://commitfest.postgresql.org/action/patch_view?id=816 Unfortunately, I was sent it with content-disposition: inline by mistake, as result, web interface divided it by two independent parts. Also this patch for 9.1 To resolve this issue, I was rebased this patch to current master (bc97c38) and send it as attachment. Here it is:
>From 489ce7f9e8ccea9d760504d3b100b67d11968516 Mon Sep 17 00:00:00 2001 From: Sergey Burladyan <eshkin...@gmail.com> Date: Tue, 28 Feb 2012 04:41:15 +0400 Subject: [PATCH] Fix NLS text width and pg_wcswidth function --- src/bin/psql/describe.c | 4 ++-- src/bin/psql/mbprint.c | 7 ++++--- src/bin/psql/mbprint.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 4eee4be..de89b09 100644 *** a/src/bin/psql/describe.c --- b/src/bin/psql/describe.c *************** describeOneTableDetails(const char *sche *** 2165,2171 **** if (i == 0) printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0)); else ! printfPQExpBuffer(&buf, "%*s %s", (int) strlen(s), "", PQgetvalue(result, i, 0)); if (i < tuples - 1) appendPQExpBuffer(&buf, ","); --- 2165,2171 ---- if (i == 0) printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0)); else ! printfPQExpBuffer(&buf, "%*s %s", pg_wcswidth(s, strlen(s), pset.encoding), "", PQgetvalue(result, i, 0)); if (i < tuples - 1) appendPQExpBuffer(&buf, ","); *************** describeOneTableDetails(const char *sche *** 2206,2212 **** ct, PQgetvalue(result, i, 0)); else printfPQExpBuffer(&buf, "%*s %s", ! (int) strlen(ct), "", PQgetvalue(result, i, 0)); if (i < tuples - 1) appendPQExpBuffer(&buf, ","); --- 2206,2212 ---- ct, PQgetvalue(result, i, 0)); else printfPQExpBuffer(&buf, "%*s %s", ! pg_wcswidth(ct, strlen(ct), pset.encoding), "", PQgetvalue(result, i, 0)); if (i < tuples - 1) appendPQExpBuffer(&buf, ","); diff --git a/src/bin/psql/mbprint.c b/src/bin/psql/mbprint.c index 32fc756..f246d00 100644 *** a/src/bin/psql/mbprint.c --- b/src/bin/psql/mbprint.c *************** mb_utf_validate(unsigned char *pwcs) *** 172,178 **** * only appear on one line. OTOH it is easier to use if this applies to you. */ int ! pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding) { int width = 0; --- 172,178 ---- * only appear on one line. OTOH it is easier to use if this applies to you. */ int ! pg_wcswidth(const char *pwcs, size_t len, int encoding) { int width = 0; *************** pg_wcswidth(const unsigned char *pwcs, s *** 181,195 **** int chlen, chwidth; ! chlen = PQmblen((const char *) pwcs, encoding); if (chlen > len) break; /* Invalid string */ ! chwidth = PQdsplen((const char *) pwcs, encoding); if (chwidth > 0) width += chwidth; pwcs += chlen; } return width; } --- 181,196 ---- int chlen, chwidth; ! chlen = PQmblen(pwcs, encoding); if (chlen > len) break; /* Invalid string */ ! chwidth = PQdsplen(pwcs, encoding); if (chwidth > 0) width += chwidth; pwcs += chlen; + len -= chlen; } return width; } diff --git a/src/bin/psql/mbprint.h b/src/bin/psql/mbprint.h index 83050ff..01064d3 100644 *** a/src/bin/psql/mbprint.h --- b/src/bin/psql/mbprint.h *************** struct lineptr *** 10,16 **** }; extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding); ! extern int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding); extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count); extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding, int *width, int *height, int *format_size); --- 10,16 ---- }; extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding); ! extern int pg_wcswidth(const char *pwcs, size_t len, int encoding); extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count); extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding, int *width, int *height, int *format_size); -- 1.7.9
-- Sergey Burladyan
-- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs