mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
Faster test for overflow in str2txid, from Marko.
This commit is contained in:
parent
b196b7fb72
commit
9f3bd2994c
@ -234,24 +234,27 @@ static txid
|
|||||||
str2txid(const char *s, const char **endp)
|
str2txid(const char *s, const char **endp)
|
||||||
{
|
{
|
||||||
txid val = 0;
|
txid val = 0;
|
||||||
|
txid cutoff = MAX_TXID / 10;
|
||||||
|
txid cutlim = MAX_TXID % 10;
|
||||||
|
|
||||||
for (; *s; s++)
|
for (; *s; s++)
|
||||||
{
|
{
|
||||||
txid last = val;
|
unsigned d;
|
||||||
|
|
||||||
if (*s < '0' || *s > '9')
|
if (*s < '0' || *s > '9')
|
||||||
break;
|
break;
|
||||||
|
d = *s - '0';
|
||||||
val = val * 10 + (*s - '0');
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check for overflow
|
* check for overflow
|
||||||
*/
|
*/
|
||||||
if (val > MAX_TXID || (val / 10) != last)
|
if (val > cutoff || (val == cutoff && d > cutlim))
|
||||||
{
|
{
|
||||||
val = 0;
|
val = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val = val * 10 + d;
|
||||||
}
|
}
|
||||||
if (endp)
|
if (endp)
|
||||||
*endp = s;
|
*endp = s;
|
||||||
|
Loading…
Reference in New Issue
Block a user