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

From Jeevan Chalke
Subject Re: Small patch for snapmgr.c
Date
Msg-id CAM2+6=WHzEbC_pSVTreY528OWac_6Kp4FkTQd6rq8Z8SR=MWgA@mail.gmail.com
Whole thread Raw
In response to Small patch for snapmgr.c  (Aleksander Alekseev <a.alekseev@postgrespro.ru>)
Responses Re: Small patch for snapmgr.c  (Aleksander Alekseev <a.alekseev@postgrespro.ru>)
List pgsql-hackers
Hi Aleksander,

This has already been fixed with commit 4f9f495889d3d410195c9891b58228727b340189

Thanks

On Fri, Apr 8, 2016 at 6:02 PM, Aleksander Alekseev <a.alekseev@postgrespro.ru> wrote:
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/


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers




--
Jeevan B Chalke
Principal Software Engineer, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Phone: +91 20 30589500

Website: www.enterprisedb.com
EnterpriseDB Blog: http://blogs.enterprisedb.com/
Follow us on Twitter: http://www.twitter.com/enterprisedb

This e-mail message (and any attachment) is intended for the use of the individual or entity to whom it is addressed. This message contains information from EnterpriseDB Corporation that may be privileged, confidential, or exempt from disclosure under applicable law. If you are not the intended recipient or authorized to receive this for the intended recipient, any use, dissemination, distribution, retention, archiving, or copying of this communication is strictly prohibited. If you have received this e-mail in error, please notify the sender immediately by reply e-mail and delete this message.

pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: Aggregate Push Down - Performing aggregation on foreign server
Next
From: Michael Banck
Date:
Subject: Exclude schema during pg_restore