Fix portability issue in ordered-set patch.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 24 Dec 2013 01:24:07 +0000 (20:24 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 24 Dec 2013 01:24:07 +0000 (20:24 -0500)
Overly compact coding in makeOrderedSetArgs() led to a platform dependency:
if the compiler chose to execute the subexpressions in the wrong order,
list_length() might get applied to an already-modified List, giving a
value we didn't want.  Per buildfarm.

src/backend/parser/gram.y

index 0249f5cdf3581ac8ba4146646b1c52456be2ec25..daa21005f01ce331e7374c79c325201500e84c2e 100644 (file)
@@ -13385,6 +13385,7 @@ makeOrderedSetArgs(List *directargs, List *orderedargs,
                   core_yyscan_t yyscanner)
 {
    FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
+   int         ndirectargs;
 
    /* No restriction unless last direct arg is VARIADIC */
    if (lastd->mode == FUNC_PARAM_VARIADIC)
@@ -13407,8 +13408,11 @@ makeOrderedSetArgs(List *directargs, List *orderedargs,
        orderedargs = NIL;
    }
 
+   /* don't merge into the next line, as list_concat changes directargs */
+   ndirectargs = list_length(directargs);
+
    return list_make2(list_concat(directargs, orderedargs),
-                     makeInteger(list_length(directargs)));
+                     makeInteger(ndirectargs));
 }
 
 /* insertSelectOptions()