Make parseNodeString() C idiom compatible with Visual Studio 2015.
authorNoah Misch <[email protected]>
Wed, 14 Jun 2023 12:31:54 +0000 (05:31 -0700)
committerNoah Misch <[email protected]>
Wed, 14 Jun 2023 12:31:54 +0000 (05:31 -0700)
Between v15 and now, this function's "else if" chain grew from 252 lines
to 592 lines, exceeding a compiler limit that manifests as "fatal error
C1026: parser stack overflow, program too complex (compiling source file
src/backend/nodes/readfuncs.c)".  Use "if (...)  return ...;" instead.

Reviewed by Tom Lane, Peter Eisentraut and Michael Paquier.  Not all
reviewers endorse this.

Discussion: https://postgr.es/m/20230607185458[email protected]

src/backend/nodes/gen_node_support.pl
src/backend/nodes/readfuncs.c

index b89b491d35006ae1fd1106cea4720aec7e3bbc70..72c79635781ed283476fa60f9afa528c1e8fe908 100644 (file)
@@ -924,9 +924,9 @@ foreach my $n (@node_types)
      . "\t\t\t\t_out${n}(str, obj);\n"
      . "\t\t\t\tbreak;\n";
 
-   print $rfs "\telse if (MATCH(\"$N\", "
+   print $rfs "\tif (MATCH(\"$N\", "
      . length($N) . "))\n"
-     . "\t\treturn_value = _read${n}();\n"
+     . "\t\treturn (Node *) _read${n}();\n"
      unless $no_read;
 
    next if elem $n, @custom_read_write;
index a136ae1d602a46003160bd7f03946c4b28ca58e9..97e43cbb49c9bc23e09fc3e413e06971b0d78a8b 100644 (file)
@@ -697,8 +697,6 @@ _readExtensibleNode(void)
 Node *
 parseNodeString(void)
 {
-   void       *return_value;
-
    READ_TEMP_LOCALS();
 
    /* Guard against stack overflow due to overly complex expressions */
@@ -709,16 +707,10 @@ parseNodeString(void)
 #define MATCH(tokname, namelen) \
    (length == namelen && memcmp(token, tokname, namelen) == 0)
 
-   if (false)
-       ;
 #include "readfuncs.switch.c"
-   else
-   {
-       elog(ERROR, "badly formatted node string \"%.32s\"...", token);
-       return_value = NULL;    /* keep compiler quiet */
-   }
 
-   return (Node *) return_value;
+   elog(ERROR, "badly formatted node string \"%.32s\"...", token);
+   return NULL;                /* keep compiler quiet */
 }