Re: Likely undefined behavior with some flexible arrays - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Likely undefined behavior with some flexible arrays
Date
Msg-id yjtlufdn6kaoctydjrryzt267xnls2t4lizslnbgqzhtsnohkj@fvvr3dbtvbrc
Whole thread Raw
In response to Re: Likely undefined behavior with some flexible arrays  (Andrey Borodin <x4mmm@yandex-team.ru>)
List pgsql-hackers
Hi,

On 2026-01-22 11:09:37 +0500, Andrey Borodin wrote:
> > On 22 Jan 2026, at 06:56, Andres Freund <andres@anarazel.de> wrote:
> > 
> > It'd be nice to teach
> > the compile that palloc allocates, to a) get compiler warnings for things like
> > use-after-free b) warnings for things like access-beyond-allocation.
> 
> Is there any chance to teach a compiler about short lived memory contexts?

I doubt that we can teach static analysis that anytime soon - I think you'd
need a compiler plugin for that. However I'd already be happy with getting
warnings for obvious stuff like using variables after being pfreed (even
indirectly) or running off the end of an allocation.

We certainly could improve the sanitizer integration with memory contexts, but
that obviously requires reaching the relevant paths in a problematic scenario
to be effective.

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: ReadRecentBuffer() doesn't scale well
Next
From: Hannu Krosing
Date:
Subject: Re: Patch: dumping tables data in multiple chunks in pg_dump