diff options
author | Peter Eisentraut | 2022-09-24 22:10:52 +0000 |
---|---|---|
committer | Peter Eisentraut | 2022-09-24 22:10:52 +0000 |
commit | 2cb1a5a8d4aeb63da2d6a2d22169f05c60bb5828 (patch) | |
tree | 74b93b484a998d20c9c996d0540d784d85dccd83 | |
parent | 43f4b349152d972c711592b8e8a4645aea9625f4 (diff) |
Fix reading of BitString nodes
The node tokenizer went out of its way to store BitString node values
without the leading 'b'. But everything else in the system stores the
leading 'b'. This would break if a BitString node is
read-printed-read.
Also, the node tokenizer didn't know that BitString node tokens could
also start with 'x'.
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/[email protected]
-rw-r--r-- | src/backend/nodes/read.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/backend/nodes/read.c b/src/backend/nodes/read.c index a9cb81b129..fe84f140ee 100644 --- a/src/backend/nodes/read.c +++ b/src/backend/nodes/read.c @@ -288,7 +288,7 @@ nodeTokenType(const char *token, int length) retval = T_Boolean; else if (*token == '"' && length > 1 && token[length - 1] == '"') retval = T_String; - else if (*token == 'b') + else if (*token == 'b' || *token == 'x') retval = T_BitString; else retval = OTHER_TOKEN; @@ -471,11 +471,10 @@ nodeRead(const char *token, int tok_len) break; case T_BitString: { - char *val = palloc(tok_len); + char *val = palloc(tok_len + 1); - /* skip leading 'b' */ - memcpy(val, token + 1, tok_len - 1); - val[tok_len - 1] = '\0'; + memcpy(val, token, tok_len); + val[tok_len] = '\0'; result = (Node *) makeBitString(val); break; } |