Re: Small patch for snapmgr.c

From: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
To: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Small patch for snapmgr.c
Date: 2016-08-31 08:09:32
Message-ID: CAM2+6=WHzEbC_pSVTreY528OWac_6Kp4FkTQd6rq8Z8SR=MWgA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)alekseev(at)postgrespro(dot)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(at)postgresql(dot)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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Banck 2016-08-31 08:10:53 Exclude schema during pg_restore
Previous Message Amit Langote 2016-08-31 08:03:04 Re: Aggregate Push Down - Performing aggregation on foreign server