Skip to content

Commit d6968e6

Browse files
committed
Do not allow *timestamp to be passed as NULL
The code had bugs that would cause crashes if NULL was passed as that argument (originally intended to mean not to bother returning its value), and after inspection it turns out that nothing seems interested in the case that *ts is NULL anyway. Therefore, remove the partial checks intended to support that case. Author: Michael Paquier though I didn't include a proposed Assert. Backpatch to 9.5.
1 parent 1944628 commit d6968e6

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/backend/access/transam/commit_ts.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ TransactionIdSetCommitTs(TransactionId xid, TimestampTz ts,
252252
/*
253253
* Interrogate the commit timestamp of a transaction.
254254
*
255-
* Return value indicates whether commit timestamp record was found for
256-
* given xid.
255+
* The return value indicates whether a commit timestamp record was found for
256+
* the given xid. The timestamp value is returned in *ts (which may not be
257+
* null), and the origin node for the Xid is returned in *nodeid, if it's not
258+
* null.
257259
*/
258260
bool
259261
TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts,
@@ -294,8 +296,7 @@ TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts,
294296
TransactionIdPrecedes(xid, oldestCommitTs) ||
295297
TransactionIdPrecedes(newestCommitTs, xid))
296298
{
297-
if (ts)
298-
*ts = 0;
299+
*ts = 0;
299300
if (nodeid)
300301
*nodeid = InvalidRepOriginId;
301302
return false;
@@ -312,8 +313,7 @@ TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts,
312313
LWLockAcquire(CommitTsLock, LW_SHARED);
313314
if (commitTsShared->xidLastCommit == xid)
314315
{
315-
if (ts)
316-
*ts = commitTsShared->dataLastCommit.time;
316+
*ts = commitTsShared->dataLastCommit.time;
317317
if (nodeid)
318318
*nodeid = commitTsShared->dataLastCommit.nodeid;
319319

@@ -330,8 +330,7 @@ TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts,
330330
SizeOfCommitTimestampEntry * entryno,
331331
SizeOfCommitTimestampEntry);
332332

333-
if (ts)
334-
*ts = entry.time;
333+
*ts = entry.time;
335334
if (nodeid)
336335
*nodeid = entry.nodeid;
337336

0 commit comments

Comments
 (0)