]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix cidin() to handle values above 2^31 platform-independently.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Oct 2016 16:24:46 +0000 (12:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Oct 2016 16:25:03 +0000 (12:25 -0400)
commitad8cd4baa3a451887b22b104b2dc2f53133537d4
tree5dc1fc1e25174211d8e06ca6b890fff897617393
parentb4f486b267913bb8f10cbf9d5ec6ff071e38e297
Fix cidin() to handle values above 2^31 platform-independently.

CommandId is declared as uint32, and values up to 4G are indeed legal.
cidout() handles them properly by treating the value as unsigned int.
But cidin() was just using atoi(), which has platform-dependent behavior
for values outside the range of signed int, as reported by Bart Lengkeek
in bug #14379.  Use strtoul() instead, as xidin() does.

In passing, make some purely cosmetic changes to make xidin/xidout
look more like cidin/cidout; the former didn't have a monopoly on
best practice IMO.

Neither xidin nor cidin make any attempt to throw error for invalid input.
I didn't change that here, and am not sure it's worth worrying about
since neither is really a user-facing type.  The point is just to ensure
that indubitably-valid inputs work as expected.

It's been like this for a long time, so back-patch to all supported
branches.

Report: <20161018152550.1413.6439@wrigleys.postgresql.org>
src/backend/utils/adt/xid.c