From 8a469d0a7195be4ecc65155b82c5836dfb13b920 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 12 Aug 2022 21:16:26 +0200 Subject: [PATCH v1 2/7] 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'. --- src/backend/nodes/read.c | 9 ++++----- 1 file 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; } -- 2.37.1