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

Commit 820bdcc

Browse files
committed
Remove a useless PG_GETARG_DATUM() call from jsonb_build_array.
This loop uselessly fetched the argument after the one it's currently looking at. No real harm is done since we couldn't possibly fetch off the end of memory, but it's confusing to the reader. Also remove a duplicate (and therefore confusing) PG_ARGISNULL check in jsonb_build_object. I happened to notice these things while trolling for missed null-arg checks earlier today. Back-patch to 9.5, not because there is any real bug, but just because 9.5 and HEAD are still in sync in this file and we might as well keep them so. In passing, re-pgindent.
1 parent 3ef16c4 commit 820bdcc

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/backend/utils/adt/jsonb.c

+5-11
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
721721
{
722722
ereport(ERROR,
723723
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
724-
errmsg("key value must be scalar, not array, composite, or json")));
724+
errmsg("key value must be scalar, not array, composite, or json")));
725725
}
726726
else
727727
{
@@ -1187,7 +1187,6 @@ jsonb_build_object(PG_FUNCTION_ARGS)
11871187

11881188
for (i = 0; i < nargs; i += 2)
11891189
{
1190-
11911190
/* process key */
11921191

11931192
if (PG_ARGISNULL(i))
@@ -1203,10 +1202,7 @@ jsonb_build_object(PG_FUNCTION_ARGS)
12031202
if (val_type == UNKNOWNOID && get_fn_expr_arg_stable(fcinfo->flinfo, i))
12041203
{
12051204
val_type = TEXTOID;
1206-
if (PG_ARGISNULL(i))
1207-
arg = (Datum) 0;
1208-
else
1209-
arg = CStringGetTextDatum(PG_GETARG_POINTER(i));
1205+
arg = CStringGetTextDatum(PG_GETARG_POINTER(i));
12101206
}
12111207
else
12121208
{
@@ -1215,7 +1211,7 @@ jsonb_build_object(PG_FUNCTION_ARGS)
12151211
if (val_type == InvalidOid || val_type == UNKNOWNOID)
12161212
ereport(ERROR,
12171213
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1218-
errmsg("argument %d: could not determine data type", i + 1)));
1214+
errmsg("argument %d: could not determine data type", i + 1)));
12191215

12201216
add_jsonb(arg, false, &result, val_type, true);
12211217

@@ -1238,9 +1234,8 @@ jsonb_build_object(PG_FUNCTION_ARGS)
12381234
if (val_type == InvalidOid || val_type == UNKNOWNOID)
12391235
ereport(ERROR,
12401236
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1241-
errmsg("argument %d: could not determine data type", i + 2)));
1237+
errmsg("argument %d: could not determine data type", i + 2)));
12421238
add_jsonb(arg, PG_ARGISNULL(i + 1), &result, val_type, false);
1243-
12441239
}
12451240

12461241
result.res = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL);
@@ -1283,7 +1278,6 @@ jsonb_build_array(PG_FUNCTION_ARGS)
12831278
for (i = 0; i < nargs; i++)
12841279
{
12851280
val_type = get_fn_expr_argtype(fcinfo->flinfo, i);
1286-
arg = PG_GETARG_DATUM(i + 1);
12871281
/* see comments in jsonb_build_object above */
12881282
if (val_type == UNKNOWNOID && get_fn_expr_arg_stable(fcinfo->flinfo, i))
12891283
{
@@ -1300,7 +1294,7 @@ jsonb_build_array(PG_FUNCTION_ARGS)
13001294
if (val_type == InvalidOid || val_type == UNKNOWNOID)
13011295
ereport(ERROR,
13021296
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1303-
errmsg("argument %d: could not determine data type", i + 1)));
1297+
errmsg("argument %d: could not determine data type", i + 1)));
13041298
add_jsonb(arg, PG_ARGISNULL(i), &result, val_type, false);
13051299
}
13061300

0 commit comments

Comments
 (0)