Re: Clang UndefinedBehaviorSanitize (Postgres14) Detected undefined-behavior

Alvaro Herrera <alvherre@2ndquadrant.com>

From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Ranier Vilela <ranier.vf@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Peter Geoghegan <pg@bowt.ie>, Noah Misch <noah@leadboat.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-08-31T17:00:50Z
Lists: pgsql-hackers
On 2020-Aug-31, Ranier Vilela wrote:

> More troubles with undefined-behavior.
> 
> This type of code can leaves overflow:
> var = (cast) (expression);
> diff = (int32) (id1 - id2);
> 
> See:
>     diff64 =  ((long int) d1 - (long int) d2);
>     diff64=-4294901760

Did you compile this with gcc -fwrapv?

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



Commits

  1. Avoid memcpy() with a NULL source pointer and count == 0

  2. Avoid calling memcpy() with a NULL source pointer and count == 0.