BUG #5416: int4inc() is wrong

From: "John Regehr" <regehr(at)cs(dot)utah(dot)edu>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #5416: int4inc() is wrong
Date: 2010-04-13 05:44:28
Message-ID: 201004130544.o3D5iS45040175@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 5416
Logged by: John Regehr
Email address: regehr(at)cs(dot)utah(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Fujii Masao 2010-04-13 06:22:53 Re: Possible alpha5 SR bug
Previous Message Jeff Davis 2010-04-13 04:36:02 Possible alpha5 SR bug