mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
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.
This commit is contained in:
parent
5191e357cf
commit
d80e73f229
@ -32,6 +32,8 @@
|
|||||||
#include "utils/datum.h"
|
#include "utils/datum.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
|
|
||||||
|
static void outChar(StringInfo str, char c);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Macros to simplify output of different kinds of fields. Use these
|
* Macros to simplify output of different kinds of fields. Use these
|
||||||
@ -62,7 +64,8 @@
|
|||||||
|
|
||||||
/* Write a char field (ie, one ascii character) */
|
/* Write a char field (ie, one ascii character) */
|
||||||
#define WRITE_CHAR_FIELD(fldname) \
|
#define WRITE_CHAR_FIELD(fldname) \
|
||||||
appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
|
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
|
||||||
|
outChar(str, node->fldname))
|
||||||
|
|
||||||
/* Write an enumerated-type field as an integer code */
|
/* Write an enumerated-type field as an integer code */
|
||||||
#define WRITE_ENUM_FIELD(fldname, enumtype) \
|
#define WRITE_ENUM_FIELD(fldname, enumtype) \
|
||||||
@ -140,6 +143,21 @@ outToken(StringInfo str, const char *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert one char. Goes through outToken() so that special characters are
|
||||||
|
* escaped.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
outChar(StringInfo str, char c)
|
||||||
|
{
|
||||||
|
char in[2];
|
||||||
|
|
||||||
|
in[0] = c;
|
||||||
|
in[1] = '\0';
|
||||||
|
|
||||||
|
outToken(str, in);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_outList(StringInfo str, const List *node)
|
_outList(StringInfo str, const List *node)
|
||||||
{
|
{
|
||||||
|
@ -86,7 +86,8 @@
|
|||||||
#define READ_CHAR_FIELD(fldname) \
|
#define READ_CHAR_FIELD(fldname) \
|
||||||
token = pg_strtok(&length); /* skip :fldname */ \
|
token = pg_strtok(&length); /* skip :fldname */ \
|
||||||
token = pg_strtok(&length); /* get field value */ \
|
token = pg_strtok(&length); /* get field value */ \
|
||||||
local_node->fldname = token[0]
|
/* avoid overhead of calling debackslash() for one char */ \
|
||||||
|
local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])
|
||||||
|
|
||||||
/* Read an enumerated-type field that was written as an integer code */
|
/* Read an enumerated-type field that was written as an integer code */
|
||||||
#define READ_ENUM_FIELD(fldname, enumtype) \
|
#define READ_ENUM_FIELD(fldname, enumtype) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user