]> granicus.if.org Git - postgresql/commitdiff
Avoid using sprintf() for a simple octal conversion in PQescapeByteaInternal.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 10 Sep 2008 17:01:07 +0000 (17:01 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 10 Sep 2008 17:01:07 +0000 (17:01 +0000)
Improves performance, per suggestion from Rudolf Leitgeb (bug #4414).
The backend did this right already, but not libpq.

src/interfaces/libpq/fe-exec.c

index 50b5c7bcf7c37d0d7fe3010ce081dc3d862970ea..149a0b73f6bb4efa4b8a0a696b0cab2b0ece94bd 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.196 2008/06/23 21:10:49 momjian Exp $
+ *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.197 2008/09/10 17:01:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2763,10 +2763,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 == '\'')
                {