Small patch for snapmgr.c - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject Small patch for snapmgr.c
Date
Msg-id 20160408153217.379a0b7e@fujitsu
Whole thread Raw
Responses Re: Small patch for snapmgr.c
List pgsql-hackers
Hello

Currently there is a following piece of code in snapmgr.c:

```
/* Copy all required fields */
snapshot = (Snapshot) MemoryContextAlloc(TopTransactionContext, size);
snapshot->satisfies = HeapTupleSatisfiesMVCC;
snapshot->xmin = serialized_snapshot->xmin;
snapshot->xmax = serialized_snapshot->xmax;
snapshot->xip = NULL;
snapshot->xcnt = serialized_snapshot->xcnt;
snapshot->subxip = NULL;
/* ... */

/* Copy XIDs, if present. */
if (serialized_snapshot->xcnt > 0)
{
    snapshot->xip = (TransactionId *) (snapshot + 1);
    memcpy(snapshot->xip, serialized_xids,
           serialized_snapshot->xcnt * sizeof(TransactionId));
}

/* Copy SubXIDs, if present. */
if (serialized_snapshot->subxcnt > 0)
{
    snapshot->subxip = snapshot->xip + serialized_snapshot->xcnt;
    memcpy(snapshot->subxip, ...
```

It assumes that subxcnt > 0 iff xcnt > 0. As I understand this is true.
At least I hope so, otherwise this code can call memcpy passing NULL as
a first argument. But Clang Static Analyzer is not aware of all this:

http://afiskon.ru/s/db/5c956077e9_snapmgr.png

I propose a patch that makes static analyzers happy and makes intention
of this code a little more obvious.

--
Best regards,
Aleksander Alekseev
http://eax.me/

Attachment

pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: Lower msvc build verbosity level
Next
From: Michael Paquier
Date:
Subject: Re: Lower msvc build verbosity level