summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2017-05-29 22:51:56 +0000
committerTom Lane2017-05-29 22:51:56 +0000
commite45c5be99d08d7bb6708d7bb1dd0f5d99798c6aa (patch)
tree8e49f4b90ada4e0d49d94c9ff9c34bcf2a349eb0
parentf3db7f164a29c5cbdc1d6d5d0d23854df58783c1 (diff)
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 cf35346e8, so no need for back-patch. Nikita Glukhov Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/backend/utils/adt/jsonfuncs.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index ab9a745234..bfd6cd9cbc 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -308,14 +308,14 @@ typedef struct JsObject
((jsv)->is_json ? (jsv)->val.json.type == JSON_TOKEN_STRING \
: ((jsv)->val.jsonb && (jsv)->val.jsonb->type == jbvString))
-#define JsObjectSize(jso) \
+#define JsObjectIsEmpty(jso) \
((jso)->is_json \
- ? hash_get_num_entries((jso)->val.json_hash) \
- : !(jso)->val.jsonb_cont || JsonContainerSize((jso)->val.jsonb_cont))
+ ? hash_get_num_entries((jso)->val.json_hash) == 0 \
+ : ((jso)->val.jsonb_cont == NULL || \
+ JsonContainerSize((jso)->val.jsonb_cont) == 0))
-#define JsObjectIsEmpty(jso) (JsObjectSize(jso) == 0)
-
-#define JsObjectFree(jso) do { \
+#define JsObjectFree(jso) \
+ do { \
if ((jso)->is_json) \
hash_destroy((jso)->val.json_hash); \
} while (0)