Re: Non-decimal integer literals

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: John Naylor <john(dot)naylor(at)enterprisedb(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Non-decimal integer literals
Date: 2022-11-30 23:11:56
Message-ID: CAApHDvqOe9Oip=j2UB8FZCKrPLrrY4OHDe96qNWnaYQeb5mgwg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 1 Dec 2022 at 00:34, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-11-30 23:33:06 Re: Strange failure on mamba
Previous Message David G. Johnston 2022-11-30 22:58:36 Re: pgsql: Revoke PUBLIC CREATE from public schema, now owned by pg_databas