diff options
author | Joe Conway <mail@joeconway.com> | 2003-11-30 20:52:37 +0000 |
---|---|---|
committer | Joe Conway <mail@joeconway.com> | 2003-11-30 20:52:37 +0000 |
commit | 8582f21afdb0a9241b915e56fc2ddb50dcd0509c (patch) | |
tree | c424d69f32e09ae56d0188c2616756955323e9b6 /src/backend/utils/adt/varlena.c | |
parent | 005887d1c07c1ee2264bbc5334a0fc78cd148b78 (diff) |
Make PQescapeBytea and byteaout consistent with each other, and
octal escape all octets outside the range 0x20 to 0x7e. This fixes
the problem pointed out by Sergey Yatskevich here:
http://archives.postgresql.org/pgsql-bugs/2003-11/msg00140.php
Diffstat (limited to 'src/backend/utils/adt/varlena.c')
-rw-r--r-- | src/backend/utils/adt/varlena.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index e0bf6b68576..9c3faaf2a4c 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.92.2.1 2003/04/23 18:19:23 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.92.2.2 2003/11/30 20:52:37 joe Exp $ * *------------------------------------------------------------------------- */ @@ -174,10 +174,10 @@ byteaout(PG_FUNCTION_ARGS) { if (*vp == '\\') len += 2; - else if (isprint((unsigned char) *vp)) - len++; - else + else if ((unsigned char) *vp < 0x20 || (unsigned char) *vp > 0x7e) len += 4; + else + len++; } rp = result = (char *) palloc(len); vp = vlena->vl_dat; @@ -188,9 +188,7 @@ byteaout(PG_FUNCTION_ARGS) *rp++ = '\\'; *rp++ = '\\'; } - else if (isprint((unsigned char) *vp)) - *rp++ = *vp; - else + else if ((unsigned char) *vp < 0x20 || (unsigned char) *vp > 0x7e) { val = *vp; rp[0] = '\\'; @@ -201,6 +199,8 @@ byteaout(PG_FUNCTION_ARGS) rp[1] = DIG(val & 03); rp += 4; } + else + *rp++ = *vp; } *rp = '\0'; PG_RETURN_CSTRING(result); |