Re: pgsql: Remove unnecessary uses of Abs()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: Re: pgsql: Remove unnecessary uses of Abs()
Date: 2022-10-07 14:38:16
Message-ID: 3155926.1665153496@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Peter Eisentraut <peter(at)eisentraut(dot)org> writes:
> Remove unnecessary uses of Abs()

Re-reading this, I noticed something that's probably not good:
in ecpg/pgtypeslib/interval.c you did

- sprintf(cp, "%02d.%0*d", abs(sec), precision, (int) Abs(fsec));
+ sprintf(cp, "%02d.%0*d", abs(sec), precision, abs(fsec));

(in 2 places). I think this has possibly broken the direction of rounding
for negative values, because we'll now truncate to integer before changing
sign. Maybe it's okay but you have to make assumptions about what it'll
do. Safer would have been

+ sprintf(cp, "%02d.%0*d", abs(sec), precision, (int) fabs(fsec));

There is similar-looking coding in remove_gene(), but I didn't check
the data type involved.

regards, tom lane

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Alvaro Herrera 2022-10-07 17:39:07 pgsql: Fix self-referencing foreign keys with partitioned tables
Previous Message Peter Eisentraut 2022-10-07 14:20:05 pgsql: Convert macros to static inline functions (rel.h)