diff options
author | Nathan Bossart <nathan@postgresql.org> | 2024-08-16 11:24:44 -0500 |
---|---|---|
committer | Nathan Bossart <nathan@postgresql.org> | 2024-08-16 11:24:44 -0500 |
commit | 108d2adb9e9e084cd57bf514d06ef4b954719ffa (patch) | |
tree | 761375cd60256cba90448bf1689b742c757e97b7 /src/backend/utils/adt/jsonfuncs.c | |
parent | 95b856de23c72bbb46b7c5430fa6897002d2908e (diff) | |
download | postgresql-108d2adb9e9e084cd57bf514d06ef4b954719ffa.tar.gz postgresql-108d2adb9e9e084cd57bf514d06ef4b954719ffa.zip |
Remove dependence on -fwrapv semantics in jsonb.
This commit updates a couple of places in the jsonb code to no
longer rely on signed integer wrapping for correctness. Like
commit 9e9a2b7031, this is intended to move us closer towards
removing -fwrapv, which may enable some compiler optimizations.
However, there is presently no plan to actually remove that
compiler option in the near future.
This commit makes use of the newly introduced pg_abs_s32() routine
to negate a signed integer (that is known to be negative) for
comparison with an unsigned integer. In passing, change one use of
INT_MIN to the more portable PG_INT32_MIN.
Reported-by: Alexander Lakhin
Author: Joseph Koshakow
Reviewed-by: Jian He
Discussion: https://postgr.es/m/CAAvxfHdBPOyEGS7s%2Bxf4iaW0-cgiq25jpYdWBqQqvLtLe_t6tw%40mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/jsonfuncs.c')
-rw-r--r-- | src/backend/utils/adt/jsonfuncs.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 5ecb9fffae2..1f8ea51e6ad 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -18,6 +18,7 @@ #include "access/htup_details.h" #include "catalog/pg_type.h" +#include "common/int.h" #include "common/jsonapi.h" #include "common/string.h" #include "fmgr.h" @@ -946,7 +947,7 @@ jsonb_array_element(PG_FUNCTION_ARGS) { uint32 nelements = JB_ROOT_COUNT(jb); - if (-element > nelements) + if (pg_abs_s32(element) > nelements) PG_RETURN_NULL(); else element += nelements; @@ -5426,7 +5427,7 @@ setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls, if (idx < 0) { - if (-idx > nelems) + if (pg_abs_s32(idx) > nelems) { /* * If asked to keep elements position consistent, it's not allowed @@ -5438,7 +5439,7 @@ setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls, errmsg("path element at position %d is out of range: %d", level + 1, idx))); else - idx = INT_MIN; + idx = PG_INT32_MIN; } else idx = nelems + idx; |