Re: [PATCH][BUG FIX] Pointer arithmetic with NULL - Mailing list pgsql-hackers

From Tomas Vondra
Subject Re: [PATCH][BUG FIX] Pointer arithmetic with NULL
Date
Msg-id 20191122200741.rtt2chpc7ni7thhj@development
Whole thread Raw
In response to [PATCH][BUG FIX] Pointer arithmetic with NULL  (Ranier Vilela <ranier_gyn@hotmail.com>)
List pgsql-hackers
On Fri, Nov 22, 2019 at 05:19:11PM +0000, Ranier Vilela wrote:
>Hi,
>Pointer addition with NULL, is technically undefined behavior.
>
>Best regards.
>Ranier Vilela
>
>--- \dll\postgresql-12.0\a\backend\access\transam\xlog.c    Mon Sep 30 17:06:55 2019
>+++ xlog.c    Fri Nov 22 13:57:17 2019
>@@ -1861,7 +1861,7 @@
>     {
>         Assert(((XLogPageHeader) cachedPos)->xlp_magic == XLOG_PAGE_MAGIC);
>         Assert(((XLogPageHeader) cachedPos)->xlp_pageaddr == ptr - (ptr % XLOG_BLCKSZ));
>-        return cachedPos + ptr % XLOG_BLCKSZ;
>+        return ptr % XLOG_BLCKSZ;
>     }
>
>     /*

But the value is not necessarily NULL, because it's defined like this:

    static char *cachedPos = NULL;

that is, it's a static value - i.e. retained across multiple calls. The
question is whether we can get into that branch before it's set, but
it's certainly not correct to just remove it ...


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: WAL archive is lost
Next
From: Tom Lane
Date:
Subject: Re: Why overhead of SPI is so large?