Skip to content

Commit bacf7b2

Browse files
committed
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.
1 parent 3c221c3 commit bacf7b2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.196 2008/06/23 21:10:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.197 2008/09/10 17:01:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2763,10 +2763,14 @@ PQescapeByteaInternal(PGconn *conn,
27632763
{
27642764
if (*vp < 0x20 || *vp > 0x7e)
27652765
{
2766+
int val = *vp;
2767+
27662768
if (!std_strings)
27672769
*rp++ = '\\';
2768-
(void) sprintf((char *) rp, "\\%03o", *vp);
2769-
rp += 4;
2770+
*rp++ = '\\';
2771+
*rp++ = (val >> 6) + '0';
2772+
*rp++ = ((val >> 3) & 07) + '0';
2773+
*rp++ = (val & 07) + '0';
27702774
}
27712775
else if (*vp == '\'')
27722776
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy