Re: Non-decimal integer literals - Mailing list pgsql-hackers

From David Rowley
Subject Re: Non-decimal integer literals
Date
Msg-id CAApHDvqOe9Oip=j2UB8FZCKrPLrrY4OHDe96qNWnaYQeb5mgwg@mail.gmail.com
Whole thread Raw
In response to Re: Non-decimal integer literals  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: Non-decimal integer literals  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Thu, 1 Dec 2022 at 00:34, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> So something
> like:
>
>     // Accumulate positive value using unsigned int, with approximate
>     // overflow check. If acc >= 1 - INT_MIN / 10, then acc * 10 is
>     // sure to exceed -INT_MIN.
>     unsigned int cutoff = 1 - INT_MIN / 10;
>     unsigned int acc = 0;
>
>     while (*ptr && isdigit((unsigned char) *ptr))
>     {
>         if (unlikely(acc >= cutoff))
>             goto out_of_range;
>         acc = acc * 10 + (*ptr - '0');
>         ptr++;
>     }
>
> and similar for other bases, allowing the coding for all bases to be
> kept similar.

Seems like a good idea to me. Couldn't the cutoff check just be "acc >
INT_MAX / 10"?

> I think it's probably best to consider this as a follow-on patch
> though. It shouldn't delay getting the main feature committed.

I agree that it should be a separate patch.  But thinking about what
Tom mentioned in [1], I had in mind this patch would need to wait
until the new standard is out so that we have a more genuine reason
for breaking existing queries.

I've drafted up a full patch for improving the current base-10 code,
so I'll go post that on another thread.

David

[1] https://postgr.es/m/3260805.1631106874@sss.pgh.pa.us



pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: pgsql: Revoke PUBLIC CREATE from public schema, now owned by pg_databas
Next
From: Tom Lane
Date:
Subject: Re: Strange failure on mamba