Skip to content

Commit 9ddf251

Browse files
committed
Handle NULL fields in WRITE_INDEX_ARRAY
Unlike existing WRITE_*_ARRAY macros, WRITE_INDEX_ARRAY needs to handle the case that the field is NULL. We already have the convention to print NULL fields as "<>", so we do that here as well. There is currently no corresponding read function for this, so reading this back in is not implemented, but it could be if needed. Reported-by: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/CAMbWs4-LN%3DbF8f9eU2R94dJtF54DfDvBq%2BovqHnOQqbinYDrUw%40mail.gmail.com
1 parent 06cafd6 commit 9ddf251

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/backend/nodes/outfuncs.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,18 @@ static void outChar(StringInfo str, char c);
124124
appendStringInfo(str, " %u", node->fldname[i]); \
125125
} while(0)
126126

127+
/*
128+
* This macro supports the case that the field is NULL. For the other array
129+
* macros, that is currently not needed.
130+
*/
127131
#define WRITE_INDEX_ARRAY(fldname, len) \
128132
do { \
129133
appendStringInfoString(str, " :" CppAsString(fldname) " "); \
130-
for (int i = 0; i < len; i++) \
131-
appendStringInfo(str, " %u", node->fldname[i]); \
134+
if (node->fldname) \
135+
for (int i = 0; i < len; i++) \
136+
appendStringInfo(str, " %u", node->fldname[i]); \
137+
else \
138+
appendStringInfoString(str, "<>"); \
132139
} while(0)
133140

134141
#define WRITE_INT_ARRAY(fldname, len) \

0 commit comments

Comments
 (0)