1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00

fix overflow (still one test fails)

This commit is contained in:
Kenichi Ishigaki 2010-06-17 02:48:49 +00:00
parent 338df4e2ac
commit 28a016a78b
2 changed files with 25 additions and 5 deletions

View file

@ -128,15 +128,29 @@ static int
sqlite_is_number(pTHX_ const char *v)
{
const char *z = v;
int i;
int i, neg;
int digit = 0;
int precision = 0;
double f;
char str[30], format[10];
if (*z == '+' || *z == '-') z++;
if (*z == '-') { neg = 1; z++; }
else if (*z == '+') { neg = 0; z++; }
else { neg = 0; }
if (!isdigit(*z)) return 0;
z++;
while (isdigit(*z)) { z++; }
while (isdigit(*z)) { digit++; z++; }
if (digit > 19) return 0; /* too large for i64 */
if (digit == 19) {
int c;
char tmp[19];
strncpy(tmp, v, z - v + 1);
c = memcmp(tmp, "922337203685477580", 18) * 10;
if (c == 0) {
c = tmp[18] - '8';
}
if (c < neg) return 0;
}
if (*z == '.') {
z++;
if (!isdigit(*z)) return 0;
@ -148,6 +162,7 @@ sqlite_is_number(pTHX_ const char *v)
if (!isdigit(*z)) return 0;
while (isdigit(*z)) { z++; }
}
sprintf(str, "%i", atoi(v));
if (strEQ(str, v)) return 1;
sprintf(format, "%%.%df", precision);

View file

@ -21,15 +21,20 @@ my @values = qw/
0. .123
-1 -1.0 -1.0e-001 -0000 -0101 -002.00
+1 +1.0 +1.0e-001 +0000 +0101 +002.00
1234567890123456789012345678901234567890
-1234567890123456789012345678901234567890
+1234567890123456789012345678901234567890
*1234567890123456789012345678901234567890
-9223372036854775808 +9223372036854775807
/;
plan tests => @values * 2 + 1;
plan tests => @values * 3 + 1;
# no type specification
for my $value (@values) {
my $dbh = connect_ok( RaiseError => 1, AutoCommit => 1 );
$dbh->do('create table foo (string)');
$dbh->do('insert into foo values(?)', undef, $value);
ok $dbh->do('insert into foo values(?)', undef, $value), "inserting $value";
my ($got) = $dbh->selectrow_array('select string from foo where string = ?', undef, $value);
ok defined $got && $got eq $value, "got: $got value: $value";
}