Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2cb1a5a

Browse files
committed
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 <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/4159834.1657405226@sss.pgh.pa.us
1 parent 43f4b34 commit 2cb1a5a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/backend/nodes/read.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ nodeTokenType(const char *token, int length)
288288
retval = T_Boolean;
289289
else if (*token == '"' && length > 1 && token[length - 1] == '"')
290290
retval = T_String;
291-
else if (*token == 'b')
291+
else if (*token == 'b' || *token == 'x')
292292
retval = T_BitString;
293293
else
294294
retval = OTHER_TOKEN;
@@ -471,11 +471,10 @@ nodeRead(const char *token, int tok_len)
471471
break;
472472
case T_BitString:
473473
{
474-
char *val = palloc(tok_len);
474+
char *val = palloc(tok_len + 1);
475475

476-
/* skip leading 'b' */
477-
memcpy(val, token + 1, tok_len - 1);
478-
val[tok_len - 1] = '\0';
476+
memcpy(val, token, tok_len);
477+
val[tok_len] = '\0';
479478
result = (Node *) makeBitString(val);
480479
break;
481480
}

0 commit comments

Comments
 (0)