Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd80e73f

Browse files
committed
Fix output of char node fields
WRITE_CHAR_FIELD() didn't do any escaping, so that for example a zerobyte would cause the whole output string to be truncated. To fix, passthe char through outToken(), so it is escaped like a string. Adjust thereading side to handle this.
1 parent5191e35 commitd80e73f

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+
staticvoidoutChar(StringInfostr,charc);
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
#defineWRITE_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
#defineWRITE_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+
staticvoid
151+
outChar(StringInfostr,charc)
152+
{
153+
charin[2];
154+
155+
in[0]=c;
156+
in[1]='\0';
157+
158+
outToken(str,in);
159+
}
160+
143161
staticvoid
144162
_outList(StringInfostr,constList*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
#defineREAD_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
#defineREAD_ENUM_FIELD(fldname,enumtype) \

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp