Skip to content

Commit e45c5be

Browse files
committed
Fix thinko in JsObjectSize() macro.
The macro gave the wrong answers for a JsObject with is_json == 0: it would return 1 if jsonb_cont == NULL, or if that wasn't NULL, it would return 1 for any non-zero size. We could fix that, but the only use of this macro at present is in the JsObjectIsEmpty() macro, so it seems simpler and clearer to get rid of JsObjectSize() and put corrected logic into JsObjectIsEmpty(). Thinko in commit cf35346, so no need for back-patch. Nikita Glukhov Discussion: https://postgr.es/m/fbd1d566-bba0-a3de-d6d0-d3b1d7c24ff2@postgrespro.ru
1 parent f3db7f1 commit e45c5be

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/backend/utils/adt/jsonfuncs.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ typedef struct JsObject
308308
((jsv)->is_json ? (jsv)->val.json.type == JSON_TOKEN_STRING \
309309
: ((jsv)->val.jsonb && (jsv)->val.jsonb->type == jbvString))
310310

311-
#define JsObjectSize(jso) \
311+
#define JsObjectIsEmpty(jso) \
312312
((jso)->is_json \
313-
? hash_get_num_entries((jso)->val.json_hash) \
314-
: !(jso)->val.jsonb_cont || JsonContainerSize((jso)->val.jsonb_cont))
313+
? hash_get_num_entries((jso)->val.json_hash) == 0 \
314+
: ((jso)->val.jsonb_cont == NULL || \
315+
JsonContainerSize((jso)->val.jsonb_cont) == 0))
315316

316-
#define JsObjectIsEmpty(jso) (JsObjectSize(jso) == 0)
317-
318-
#define JsObjectFree(jso) do { \
317+
#define JsObjectFree(jso) \
318+
do { \
319319
if ((jso)->is_json) \
320320
hash_destroy((jso)->val.json_hash); \
321321
} while (0)

0 commit comments

Comments
 (0)