Re: DEREF_AFTER_NULL: src/common/jsonapi.c:2529

Jacob Champion <jacob.champion@enterprisedb.com>

From: Jacob Champion <jacob.champion@enterprisedb.com>
To: Andreas Karlsson <andreas@proxel.se>
Cc: Галкин Сергей <galkin@rutoken.ru>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-06T17:57:22Z
Lists: pgsql-hackers
On Mon, Apr 6, 2026 at 4:59 AM Andreas Karlsson <andreas@proxel.se> wrote:
> The code is correct but a bit confusing.

Yeah, it's not great. The need for this (security-critical!) code to
wrangle three separate allocation conventions is error-prone, to say
the least.

> If someone has a patch improving readability

Suggestions?

> adding this noop NULL check to silence a false positive from a
> static analyzer does not seem like an improvement.

We do occasionally merge code to silence false positives, and we could
maybe do something with pg_assume() here, but I agree that it'd be
better to refactor it so that it's obviously correct.

--Jacob