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
This commit is contained in:
Peter Eisentraut 2022-09-24 18:10:52 -04:00
parent 43f4b34915
commit 2cb1a5a8d4
1 changed files with 4 additions and 5 deletions

View File

@ -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;
}