Thread: BUG #4743: potential bug between int and uint

BUG #4743: potential bug between int and uint

From
"MATSUDA, Daiki"
Date:
The following bug has been logged online:

Bug reference:      4743
Logged by:          MATSUDA, Daiki
Email address:      d.matuda@gmail.com
PostgreSQL version: 8.3.6
Operating system:   Linux
Description:        potential bug between int and uint
Details:

diff -uNrp ./src/backend/storage/ipc/procarray.c.bk
./src/backend/storage/ipc/procarray.c
--- ./src/backend/storage/ipc/procarray.c.bk    2009-03-05
10:23:03.000000000 +0900
+++ ./src/backend/storage/ipc/procarray.c       2009-03-05
10:25:20.000000000 +0900
@@ -662,8 +662,8 @@ GetSnapshotData(Snapshot snapshot, bool
        TransactionId xmax;
        TransactionId globalxmin;
        int                     index;
-       int                     count = 0;
-       int                     subcount = 0;
+       uint32          count = 0;
+       int32           subcount = 0;

        Assert(snapshot != NULL);

because uint32 xcnt and int32 subxcnt in Snapshot structure, same as struct
SnapshotData, is declared. and
    snapshot->xcnt = count;
    snapshot->subxcnt = subcount;
are written in GetSnapshotData() in procarray.c. It is a potential bug.

Re: BUG #4743: potential bug between int and uint

From
Tom Lane
Date:
"MATSUDA, Daiki" <d.matuda@gmail.com> writes:
> -       int                     count = 0;
> -       int                     subcount = 0;
> +       uint32          count = 0;
> +       int32           subcount = 0;

This is really unimportant, since neither counter could possibly
approach the point of overflow.  (If they could, we'd need to install
active defenses against that, not just tweak the datatypes...)

            regards, tom lane