From 07f0867c9ce8e75201be73fbe55fb2b4bb1e8861 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 10 Sep 2008 17:01:17 +0000 Subject: [PATCH] Avoid using sprintf() for a simple octal conversion in PQescapeByteaInternal. Improves performance, per suggestion from Rudolf Leitgeb (bug #4414). The backend did this right already, but not libpq. --- src/interfaces/libpq/fe-exec.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index c3bc843d02..67c944be09 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -2760,10 +2760,14 @@ PQescapeByteaInternal(PGconn *conn, { if (*vp < 0x20 || *vp > 0x7e) { + int val = *vp; + if (!std_strings) *rp++ = '\\'; - (void) sprintf((char *) rp, "\\%03o", *vp); - rp += 4; + *rp++ = '\\'; + *rp++ = (val >> 6) + '0'; + *rp++ = ((val >> 3) & 07) + '0'; + *rp++ = (val & 07) + '0'; } else if (*vp == '\'') { -- 2.39.5