Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc831593

Browse files
committed
Fix some jsonb issues found by Coverity in recent commits.
Mostly these issues concern the non-use of function results. Thesehave been changed to use (void) pushJsonbValue(...) instead of assigningthe result to a variable that gets overwritten before it is used.There is a larger issue that we should possibly examine the API forpushJsonbValue(), so that instead of returning a value it modifies astate argument. The current idiom is rather clumsy. However, changingthat requires quite a bit more work, so this change should do for themoment.
1 parent4d65e16 commitc831593

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

‎src/backend/utils/adt/jsonb.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ jsonb_build_object_noargs(PG_FUNCTION_ARGS)
11941194

11951195
memset(&result,0,sizeof(JsonbInState));
11961196

1197-
result.res=pushJsonbValue(&result.parseState,WJB_BEGIN_OBJECT,NULL);
1197+
(void)pushJsonbValue(&result.parseState,WJB_BEGIN_OBJECT,NULL);
11981198
result.res=pushJsonbValue(&result.parseState,WJB_END_OBJECT,NULL);
11991199

12001200
PG_RETURN_POINTER(JsonbValueToJsonb(result.res));
@@ -1255,7 +1255,7 @@ jsonb_build_array_noargs(PG_FUNCTION_ARGS)
12551255

12561256
memset(&result,0,sizeof(JsonbInState));
12571257

1258-
result.res=pushJsonbValue(&result.parseState,WJB_BEGIN_ARRAY,NULL);
1258+
(void)pushJsonbValue(&result.parseState,WJB_BEGIN_ARRAY,NULL);
12591259
result.res=pushJsonbValue(&result.parseState,WJB_END_ARRAY,NULL);
12601260

12611261
PG_RETURN_POINTER(JsonbValueToJsonb(result.res));
@@ -1283,7 +1283,7 @@ jsonb_object(PG_FUNCTION_ARGS)
12831283

12841284
memset(&result,0,sizeof(JsonbInState));
12851285

1286-
result.res=pushJsonbValue(&result.parseState,WJB_BEGIN_OBJECT,NULL);
1286+
(void)pushJsonbValue(&result.parseState,WJB_BEGIN_OBJECT,NULL);
12871287

12881288
switch (ndims)
12891289
{
@@ -1336,7 +1336,7 @@ jsonb_object(PG_FUNCTION_ARGS)
13361336
v.val.string.len=len;
13371337
v.val.string.val=str;
13381338

1339-
result.res=pushJsonbValue(&result.parseState,WJB_KEY,&v);
1339+
(void)pushJsonbValue(&result.parseState,WJB_KEY,&v);
13401340

13411341
if (in_nulls[i*2+1])
13421342
{
@@ -1353,7 +1353,7 @@ jsonb_object(PG_FUNCTION_ARGS)
13531353
v.val.string.val=str;
13541354
}
13551355

1356-
result.res=pushJsonbValue(&result.parseState,WJB_VALUE,&v);
1356+
(void)pushJsonbValue(&result.parseState,WJB_VALUE,&v);
13571357
}
13581358

13591359
pfree(in_datums);
@@ -1389,7 +1389,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
13891389

13901390
memset(&result,0,sizeof(JsonbInState));
13911391

1392-
result.res=pushJsonbValue(&result.parseState,WJB_BEGIN_OBJECT,NULL);
1392+
(void)pushJsonbValue(&result.parseState,WJB_BEGIN_OBJECT,NULL);
13931393

13941394
if (nkdims>1||nkdims!=nvdims)
13951395
ereport(ERROR,
@@ -1431,7 +1431,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
14311431
v.val.string.len=len;
14321432
v.val.string.val=str;
14331433

1434-
result.res=pushJsonbValue(&result.parseState,WJB_KEY,&v);
1434+
(void)pushJsonbValue(&result.parseState,WJB_KEY,&v);
14351435

14361436
if (val_nulls[i])
14371437
{
@@ -1448,7 +1448,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
14481448
v.val.string.val=str;
14491449
}
14501450

1451-
result.res=pushJsonbValue(&result.parseState,WJB_VALUE,&v);
1451+
(void)pushJsonbValue(&result.parseState,WJB_VALUE,&v);
14521452
}
14531453

14541454
result.res=pushJsonbValue(&result.parseState,WJB_END_OBJECT,NULL);

‎src/backend/utils/adt/jsonfuncs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3182,7 +3182,7 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS)
31823182
continue;
31833183

31843184
/* otherwise, do a delayed push of the key */
3185-
res=pushJsonbValue(&parseState,WJB_KEY,&k);
3185+
(void)pushJsonbValue(&parseState,WJB_KEY,&k);
31863186
}
31873187

31883188
if (type==WJB_VALUE||type==WJB_ELEM)
@@ -3191,5 +3191,7 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS)
31913191
res=pushJsonbValue(&parseState,type,NULL);
31923192
}
31933193

3194+
Assert(res!=NULL);
3195+
31943196
PG_RETURN_POINTER(JsonbValueToJsonb(res));
31953197
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp