From: | Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Small patch for snapmgr.c |
Date: | 2016-04-08 12:32:17 |
Message-ID: | 20160408153217.379a0b7e@fujitsu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 | Content-Type | Size |
---|---|---|
snapmgr-c.diff | text/x-patch | 1.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2016-04-08 12:44:55 | Re: Lower msvc build verbosity level |
Previous Message | Magnus Hagander | 2016-04-08 12:29:59 | Re: Lower msvc build verbosity level |