Re: Simplifies checks (src/bin/pg_dump/pg_backup_archiver.c)

From: Japin Li <japinli(at)hotmail(dot)com>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Simplifies checks (src/bin/pg_dump/pg_backup_archiver.c)
Date: 2026-03-10 06:12:23
Message-ID: SY7PR01MB109215ACE211279288C80AF80B646A@SY7PR01MB10921.ausprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 09 Mar 2026 at 10:07, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote:
> Hi.
>
> Per Coverity.
>
> Coverity has some alerts about the function *RestoreArchive*,
> arguing that there are null variable dereferences.
>
> I haven't done in-depth research to determine if this is correct or not.
> However, the code can be simplified to a single check that would silence notifications and protect against this issue.
>
> patch attached.

According to _allocAH(), te cannot be null.

AH->toc = pg_malloc0_object(TocEntry);

AH->toc->next = AH->toc;
AH->toc->prev = AH->toc;

So we can safely remove its null check.

diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index df8a69d3b79..137e5850f8e 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -767,7 +767,7 @@ RestoreArchive(Archive *AHX, bool append_data)
continue; /* ignore if not to be dumped at all */

/* Skip if no-tablespace is given. */
- if (ropt->noTablespace && te && te->desc &&
+ if (ropt->noTablespace && te->desc &&
(strcmp(te->desc, "TABLESPACE") == 0))
continue;

@@ -775,7 +775,7 @@ RestoreArchive(Archive *AHX, bool append_data)
* Skip DROP DATABASE/ROLES/TABLESPACE if we didn't specify
* --clean
*/
- if (!ropt->dropSchema && te && te->desc &&
+ if (!ropt->dropSchema && te->desc &&
strcmp(te->desc, "DROP_GLOBAL") == 0)
continue;

>
> best regards,
> Ranier Vilela
>
> [4. text/x-diff; simplifies-checks-pg_basebackup_archiver.patch]...

--
Regards,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-03-10 06:17:32 Re: Skipping schema changes in publication
Previous Message Xuneng Zhou 2026-03-10 06:06:12 Re: Streamify more code paths