Re: Question about integer out of range in function - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: Question about integer out of range in function
Date
Msg-id 20210521151752.GA23484@hjp.at
Whole thread Raw
In response to Question about integer out of range in function  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
On 2021-05-16 11:09:38 -0700, David G. Johnston wrote:
> On Sunday, May 16, 2021, Condor <condor@stz-bg.com> wrote:
>
>
>          new_time = fromtime * 1000; -- here is line 19
>          
>
>
> An integer times an integer results in an integer.  Period.  Neither fromtime
> nor new_time have been assigned to yet, the in-memory result of the computation
> is only allocated integer bits and if you overflow that you get an error.

This is also true in C, btw, except that in C an overflow of a signed
int is undefined behaviour while an unsigned int is required to wrap
around.

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

pgsql-general by date:

Previous
From: Ian Lawrence Barwick
Date:
Subject: Re: I have no idea why pg_dump isn't dumping all of my data
Next
From: Adrian Klaver
Date:
Subject: Re: The contents of the pg_timezone_names view bring some surprises