Re: patch: Use pg_assume in jsonb_util.c to fix GCC 15 warnings

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Dmitry Mityugov <d.mityugov@postgrespro.ru>, pgsql-hackers@postgresql.org
Date: 2025-07-12T19:23:26Z
Lists: pgsql-hackers

Attachments

After further study I've understood what was bothering me about
the logic in compareJsonbContainers (lines 280ff).  Because
JsonbIteratorNext doesn't presently guarantee to set val->type
when returning WJB_DONE, the stanza appears to be at risk of
undefined behavior should one iterator return that while the other
returns something else.  The comment fails to discuss this case,
and the code doesn't consider it either.  But in reality, the case
cannot happen for the exact same reason that WJB_END_ARRAY and
WJB_END_OBJECT can't occur: our earlier tests of object and array
structure & length matching guarantee that we can't reach the end
of one input before the other.

So I think we need to rewrite that comment and extend the assertions,
along the lines of the separate patch attached.  This gets through
check-world, which is unsurprising because if it did not we'd have
seen use-of-undefined-value Valgrind complaints long since.

I still think that we should silence the compiler warnings by
removing the undefined-ness per my previous patch.  I'm inclined
to back-patch that (for people compiling old branches with latest
compiler) but apply this bit to HEAD only (since it's just a code
clarification).

			regards, tom lane

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Clarify the ra != rb case in compareJsonbContainers().

  2. Silence uninitialized-value warnings in compareJsonbContainers().