From: Nathan Bossart Date: Fri, 16 Aug 2024 20:06:40 +0000 (-0500) Subject: Further reduce dependence on -fwrapv semantics in jsonb. X-Git-Tag: REL_18_BETA1~2107 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=1d80d6b50e6401828fc445151375f9bde3f99ac6;p=postgresql.git Further reduce dependence on -fwrapv semantics in jsonb. Commit 108d2adb9e missed updating a few places in the jsonb code that rely on signed integer wrapping for correctness. These can also be fixed by using pg_abs_s32() to negate a signed integer (that is known to be negative) for comparison with an unsigned integer. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/bfff906f-300d-81ea-83b7-f2c93845e7f2%40gmail.com --- diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 1f8ea51e6ad..62a17a26679 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -990,7 +990,7 @@ jsonb_array_element_text(PG_FUNCTION_ARGS) { uint32 nelements = JB_ROOT_COUNT(jb); - if (-element > nelements) + if (pg_abs_s32(element) > nelements) PG_RETURN_NULL(); else element += nelements; @@ -4811,7 +4811,7 @@ jsonb_delete_idx(PG_FUNCTION_ARGS) if (idx < 0) { - if (-idx > n) + if (pg_abs_s32(idx) > n) idx = n; else idx = n + idx;