From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
Cc: | Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, John Naylor <john(dot)naylor(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Non-decimal integer literals |
Date: | 2022-11-29 20:16:55 |
Message-ID: | CAApHDvry+fXyyUdPSMEfTh0ygVCQhT4RYVpPCWJ0wyTFr3UOFg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, 29 Nov 2022 at 23:11, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>
> On Wed, 23 Nov 2022 at 08:56, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> >
> > On Wed, 23 Nov 2022 at 21:54, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> > > I wonder if you'd be better off with something like:
> > >
> > > while (*ptr && isxdigit((unsigned char) *ptr))
> > > {
> > > if (unlikely(tmp & UINT64CONST(0xF000000000000000)))
> > > goto out_of_range;
> > >
> > > tmp = (tmp << 4) | hexlookup[(unsigned char) *ptr++];
> > > }
> >
> > Here's a delta diff with it changed to work that way.
> >
>
> This isn't correct, because those functions are meant to accumulate a
> negative number in "tmp".
Looks like I didn't quite look at that code closely enough.
To make that work we could just form the non-decimal versions in an
unsigned integer of the given size and then check if that's become
greater than -PG_INTXX_MIN after the loop. We'd then just need to
convert it back to its negative form.
i.e:
uint64 tmp2 = 0;
ptr += 2;
while (*ptr && isxdigit((unsigned char) *ptr))
{
if (unlikely(tmp2 & UINT64CONST(0xF000000000000000)))
goto out_of_range;
tmp2 = (tmp2 << 4) | hexlookup[(unsigned char) *ptr++];
}
if (tmp2 > -PG_INT64_MIN)
goto out_of_range;
tmp = -((int64) tmp2);
David
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2022-11-29 20:21:07 | Re: Collation version tracking for macOS |
Previous Message | Thomas Munro | 2022-11-29 20:00:46 | Re: Collation version tracking for macOS |