Skip to content

Commit d80e73f

Browse files
committed
Fix output of char node fields
WRITE_CHAR_FIELD() didn't do any escaping, so that for example a zero byte would cause the whole output string to be truncated. To fix, pass the char through outToken(), so it is escaped like a string. Adjust the reading side to handle this.
1 parent 5191e35 commit d80e73f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/backend/nodes/outfuncs.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "utils/datum.h"
3333
#include "utils/rel.h"
3434

35+
static void outChar(StringInfo str, char c);
36+
3537

3638
/*
3739
* Macros to simplify output of different kinds of fields. Use these
@@ -62,7 +64,8 @@
6264

6365
/* Write a char field (ie, one ascii character) */
6466
#define WRITE_CHAR_FIELD(fldname) \
65-
appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
67+
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
68+
outChar(str, node->fldname))
6669

6770
/* Write an enumerated-type field as an integer code */
6871
#define WRITE_ENUM_FIELD(fldname, enumtype) \
@@ -140,6 +143,21 @@ outToken(StringInfo str, const char *s)
140143
}
141144
}
142145

146+
/*
147+
* Convert one char. Goes through outToken() so that special characters are
148+
* escaped.
149+
*/
150+
static void
151+
outChar(StringInfo str, char c)
152+
{
153+
char in[2];
154+
155+
in[0] = c;
156+
in[1] = '\0';
157+
158+
outToken(str, in);
159+
}
160+
143161
static void
144162
_outList(StringInfo str, const List *node)
145163
{

src/backend/nodes/readfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
#define READ_CHAR_FIELD(fldname) \
8787
token = pg_strtok(&length); /* skip :fldname */ \
8888
token = pg_strtok(&length); /* get field value */ \
89-
local_node->fldname = token[0]
89+
/* avoid overhead of calling debackslash() for one char */ \
90+
local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])
9091

9192
/* Read an enumerated-type field that was written as an integer code */
9293
#define READ_ENUM_FIELD(fldname, enumtype) \

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