From 5cfb2abbfae32f9d73decd240a889088bf5e18e5 Mon Sep 17 00:00:00 2001 From: Andrey Borodin Date: Mon, 10 Aug 2026 10:54:14 +0500 Subject: [PATCH v1] Document GiST sorted build's parent-level invariant A final flush of a nonempty level always creates a parent level if one does not exist already. Coverity failed to infer that postcondition and reported a possible null pointer dereference in the caller. Add an assertion that makes the invariant explicit. This also avoids a more invasive refactoring in the back branches. Discussion: https://postgr.es/m/1788513.1786329441@sss.pgh.pa.us --- src/backend/access/gist/gistbuild.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c index 7f57c787f4c..82bcf98e7bc 100644 --- a/src/backend/access/gist/gistbuild.c +++ b/src/backend/access/gist/gistbuild.c @@ -434,6 +434,8 @@ gist_indexsortbuild(GISTBuildState *state) GistSortedBuildLevelState *parent; gist_indexsortbuild_levelstate_flush(state, levelstate); + /* Flushing a level creates its parent, if necessary. */ + Assert(levelstate->parent != NULL); parent = levelstate->parent; for (int i = 0; i < GIST_SORTED_BUILD_PAGE_NUM; i++) if (levelstate->pages[i]) -- 2.50.1 (Apple Git-155)