Commit c8315930 authored by Andrew Dunstan's avatar Andrew Dunstan

Fix some jsonb issues found by Coverity in recent commits.

Mostly these issues concern the non-use of function results. These
have been changed to use (void) pushJsonbValue(...) instead of assigning
the result to a variable that gets overwritten before it is used.

There is a larger issue that we should possibly examine the API for
pushJsonbValue(), so that instead of returning a value it modifies a
state argument. The current idiom is rather clumsy. However, changing
that requires quite a bit more work, so this change should do for the
moment.
parent 4d65e16a
...@@ -1194,7 +1194,7 @@ jsonb_build_object_noargs(PG_FUNCTION_ARGS) ...@@ -1194,7 +1194,7 @@ jsonb_build_object_noargs(PG_FUNCTION_ARGS)
memset(&result, 0, sizeof(JsonbInState)); memset(&result, 0, sizeof(JsonbInState));
result.res = pushJsonbValue(&result.parseState, WJB_BEGIN_OBJECT, NULL); (void) pushJsonbValue(&result.parseState, WJB_BEGIN_OBJECT, NULL);
result.res = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL); result.res = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL);
PG_RETURN_POINTER(JsonbValueToJsonb(result.res)); PG_RETURN_POINTER(JsonbValueToJsonb(result.res));
...@@ -1255,7 +1255,7 @@ jsonb_build_array_noargs(PG_FUNCTION_ARGS) ...@@ -1255,7 +1255,7 @@ jsonb_build_array_noargs(PG_FUNCTION_ARGS)
memset(&result, 0, sizeof(JsonbInState)); memset(&result, 0, sizeof(JsonbInState));
result.res = pushJsonbValue(&result.parseState, WJB_BEGIN_ARRAY, NULL); (void) pushJsonbValue(&result.parseState, WJB_BEGIN_ARRAY, NULL);
result.res = pushJsonbValue(&result.parseState, WJB_END_ARRAY, NULL); result.res = pushJsonbValue(&result.parseState, WJB_END_ARRAY, NULL);
PG_RETURN_POINTER(JsonbValueToJsonb(result.res)); PG_RETURN_POINTER(JsonbValueToJsonb(result.res));
...@@ -1283,7 +1283,7 @@ jsonb_object(PG_FUNCTION_ARGS) ...@@ -1283,7 +1283,7 @@ jsonb_object(PG_FUNCTION_ARGS)
memset(&result, 0, sizeof(JsonbInState)); memset(&result, 0, sizeof(JsonbInState));
result.res = pushJsonbValue(&result.parseState, WJB_BEGIN_OBJECT, NULL); (void) pushJsonbValue(&result.parseState, WJB_BEGIN_OBJECT, NULL);
switch (ndims) switch (ndims)
{ {
...@@ -1336,7 +1336,7 @@ jsonb_object(PG_FUNCTION_ARGS) ...@@ -1336,7 +1336,7 @@ jsonb_object(PG_FUNCTION_ARGS)
v.val.string.len = len; v.val.string.len = len;
v.val.string.val = str; v.val.string.val = str;
result.res = pushJsonbValue(&result.parseState, WJB_KEY, &v); (void) pushJsonbValue(&result.parseState, WJB_KEY, &v);
if (in_nulls[i * 2 + 1]) if (in_nulls[i * 2 + 1])
{ {
...@@ -1353,7 +1353,7 @@ jsonb_object(PG_FUNCTION_ARGS) ...@@ -1353,7 +1353,7 @@ jsonb_object(PG_FUNCTION_ARGS)
v.val.string.val = str; v.val.string.val = str;
} }
result.res = pushJsonbValue(&result.parseState, WJB_VALUE, &v); (void) pushJsonbValue(&result.parseState, WJB_VALUE, &v);
} }
pfree(in_datums); pfree(in_datums);
...@@ -1389,7 +1389,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS) ...@@ -1389,7 +1389,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
memset(&result, 0, sizeof(JsonbInState)); memset(&result, 0, sizeof(JsonbInState));
result.res = pushJsonbValue(&result.parseState, WJB_BEGIN_OBJECT, NULL); (void) pushJsonbValue(&result.parseState, WJB_BEGIN_OBJECT, NULL);
if (nkdims > 1 || nkdims != nvdims) if (nkdims > 1 || nkdims != nvdims)
ereport(ERROR, ereport(ERROR,
...@@ -1431,7 +1431,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS) ...@@ -1431,7 +1431,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
v.val.string.len = len; v.val.string.len = len;
v.val.string.val = str; v.val.string.val = str;
result.res = pushJsonbValue(&result.parseState, WJB_KEY, &v); (void) pushJsonbValue(&result.parseState, WJB_KEY, &v);
if (val_nulls[i]) if (val_nulls[i])
{ {
...@@ -1448,7 +1448,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS) ...@@ -1448,7 +1448,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
v.val.string.val = str; v.val.string.val = str;
} }
result.res = pushJsonbValue(&result.parseState, WJB_VALUE, &v); (void) pushJsonbValue(&result.parseState, WJB_VALUE, &v);
} }
result.res = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL); result.res = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL);
......
...@@ -3182,7 +3182,7 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS) ...@@ -3182,7 +3182,7 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS)
continue; continue;
/* otherwise, do a delayed push of the key */ /* otherwise, do a delayed push of the key */
res = pushJsonbValue(&parseState, WJB_KEY, &k); (void) pushJsonbValue(&parseState, WJB_KEY, &k);
} }
if (type == WJB_VALUE || type == WJB_ELEM) if (type == WJB_VALUE || type == WJB_ELEM)
...@@ -3191,5 +3191,7 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS) ...@@ -3191,5 +3191,7 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS)
res = pushJsonbValue(&parseState, type, NULL); res = pushJsonbValue(&parseState, type, NULL);
} }
Assert(res != NULL);
PG_RETURN_POINTER(JsonbValueToJsonb(res)); PG_RETURN_POINTER(JsonbValueToJsonb(res));
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment