Commit 9f3bd299 authored by Tom Lane's avatar Tom Lane

Faster test for overflow in str2txid, from Marko.

parent b196b7fb
......@@ -234,24 +234,27 @@ static txid
str2txid(const char *s, const char **endp)
{
txid val = 0;
txid cutoff = MAX_TXID / 10;
txid cutlim = MAX_TXID % 10;
for (; *s; s++)
{
txid last = val;
unsigned d;
if (*s < '0' || *s > '9')
break;
val = val * 10 + (*s - '0');
d = *s - '0';
/*
* check for overflow
*/
if (val > MAX_TXID || (val / 10) != last)
if (val > cutoff || (val == cutoff && d > cutlim))
{
val = 0;
break;
}
val = val * 10 + d;
}
if (endp)
*endp = s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment