diff options
| author | Tom Lane | 2020-06-29 21:12:38 +0000 |
|---|---|---|
| committer | Tom Lane | 2020-06-29 21:12:38 +0000 |
| commit | c410af098c46949e36607eb13689e697fa2def97 (patch) | |
| tree | 98da94dc6bc93b6919ecb5bab1e0fa916575ce47 /src/interfaces | |
| parent | f7a476f0d656bbc673474b9165cd05fa548c18c9 (diff) | |
Mop up some no-longer-necessary hacks around printf %.*s format.
Commit 54cd4f045 added some kluges to work around an old glibc bug,
namely that %.*s could misbehave if glibc thought any characters in
the supplied string were incorrectly encoded. Now that we use our
own snprintf.c implementation, we need not worry about that bug (even
if it still exists in the wild). Revert a couple of particularly
ugly hacks, and remove or improve assorted comments.
Note that there can still be encoding-related hazards here: blindly
clipping at a fixed length risks producing wrongly-encoded output
if the clip splits a multibyte character. However, code that's
doing correct multibyte-aware clipping doesn't really need a comment
about that, while code that isn't needs an explanation why not,
rather than a red-herring comment about an obsolete bug.
Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/interfaces')
| -rw-r--r-- | src/interfaces/ecpg/ecpglib/error.c | 1 | ||||
| -rw-r--r-- | src/interfaces/ecpg/pgtypeslib/dt_common.c | 3 | ||||
| -rw-r--r-- | src/interfaces/libpq/fe-misc.c | 19 |
3 files changed, 5 insertions, 18 deletions
diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c index a4e3c0d01f8..cd6c6a6819b 100644 --- a/src/interfaces/ecpg/ecpglib/error.c +++ b/src/interfaces/ecpg/ecpglib/error.c @@ -270,7 +270,6 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat) else sqlca->sqlcode = ECPG_PGSQL; - /* %.*s is safe here as long as sqlstate is all-ASCII */ ecpg_log("raising sqlstate %.*s (sqlcode %ld): %s\n", (int) sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, sqlca->sqlerrm.sqlerrmc); diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c index 81bd7aa526f..14cdf2d428b 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt_common.c +++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c @@ -826,7 +826,8 @@ EncodeDateTime(struct tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tz /* * Note: the uses of %.*s in this function would be risky if the - * timezone names ever contain non-ASCII characters. However, all + * timezone names ever contain non-ASCII characters, since we are + * not being careful to do encoding-aware clipping. However, all * TZ abbreviations in the IANA database are plain ASCII. */ diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index 9273984727a..ff840b7730d 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -68,19 +68,6 @@ PQlibVersion(void) return PG_VERSION_NUM; } -/* - * fputnbytes: print exactly N bytes to a file - * - * We avoid using %.*s here because it can misbehave if the data - * is not valid in what libc thinks is the prevailing encoding. - */ -static void -fputnbytes(FILE *f, const char *str, size_t n) -{ - while (n-- > 0) - fputc(*str++, f); -} - /* * pqGetc: get 1 character from the connection @@ -204,7 +191,7 @@ pqGetnchar(char *s, size_t len, PGconn *conn) if (conn->Pfdebug) { fprintf(conn->Pfdebug, "From backend (%lu)> ", (unsigned long) len); - fputnbytes(conn->Pfdebug, s, len); + fwrite(s, 1, len, conn->Pfdebug); fprintf(conn->Pfdebug, "\n"); } @@ -228,7 +215,7 @@ pqSkipnchar(size_t len, PGconn *conn) if (conn->Pfdebug) { fprintf(conn->Pfdebug, "From backend (%lu)> ", (unsigned long) len); - fputnbytes(conn->Pfdebug, conn->inBuffer + conn->inCursor, len); + fwrite(conn->inBuffer + conn->inCursor, 1, len, conn->Pfdebug); fprintf(conn->Pfdebug, "\n"); } @@ -250,7 +237,7 @@ pqPutnchar(const char *s, size_t len, PGconn *conn) if (conn->Pfdebug) { fprintf(conn->Pfdebug, "To backend> "); - fputnbytes(conn->Pfdebug, s, len); + fwrite(s, 1, len, conn->Pfdebug); fprintf(conn->Pfdebug, "\n"); } |
