BUG #5416: int4inc() is wrong - Mailing list pgsql-bugs

From John Regehr
Subject BUG #5416: int4inc() is wrong
Date
Msg-id 201004130544.o3D5iS45040175@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #5416: int4inc() is wrong  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      5416
Logged by:          John Regehr
Email address:      regehr@cs.utah.edu
PostgreSQL version: git head Apr 12
Operating system:   n/a
Description:        int4inc() is wrong
Details:

The overflow check in int4inc() from int.c is wrong.  The problem is that in
C, signed overflow is undefined.  Both LLVM and GCC eliminate the overflow
check in this function.  This is easy to see by looking at the asm emitted
by either compiler.

There are several easy ways to fix this code.  One would be to test arg
against INT_MAX before incrementing.  Another would be to cast arg to
unsigned, increment it, then do the check.

pgsql-bugs by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: Possible alpha5 SR bug
Next
From: Craig Ringer
Date:
Subject: Re: BUG #5418: psql exits after using tab-completion with error message