Skip Menu |

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 28785
Status: resolved
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: Thomas.Skora [...] secunet.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: User defined functions return values cause overflows in a particular range
Date: Fri, 10 Aug 2007 18:39:21 +0200
To: <bug-DBD-SQLite [...] rt.cpan.org>
From: "Skora, Thomas" <Thomas.Skora [...] secunet.com>
Hi! If a user defined function returns a value between 2^31 and 2^31-1 the value wraps around into a negative one. Following example: --------------------------------------------------- #!/usr/bin/perl use DBI; sub return_big { my ($val) = @_; return 2**$val; } if ($ARGV[0] == 2) { $dbh = DBI->connect("dbi:SQLite2:dbname=foo", "", "", { PrintError => 0 } ); } elsif ($ARGV[0] == 3) { $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "", { PrintError => 0 } ); } $dbh->func( "bignumber", 1, \&return_big, "create_function" ); for ( $i = 0; $i <= 40; $i++) { my $result = $dbh->selectrow_arrayref( "SELECT bignumber($i)" ); print "2^$i = ".$$result[0]."\n"; } --------------------------------------------------- Causes the output: --------------------------------------------------- 2^0 = 1 2^1 = 2 2^2 = 4 2^3 = 8 2^4 = 16 2^5 = 32 2^6 = 64 2^7 = 128 2^8 = 256 2^9 = 512 2^10 = 1024 2^11 = 2048 2^12 = 4096 2^13 = 8192 2^14 = 16384 2^15 = 32768 2^16 = 65536 2^17 = 131072 2^18 = 262144 2^19 = 524288 2^20 = 1048576 2^21 = 2097152 2^22 = 4194304 2^23 = 8388608 2^24 = 16777216 2^25 = 33554432 2^26 = 67108864 2^27 = 134217728 2^28 = 268435456 2^29 = 536870912 2^30 = 1073741824 2^31 = -2147483648 [Here the error occurs] 2^32 = 4294967296 2^33 = 8589934592 2^34 = 17179869184 2^35 = 34359738368 2^36 = 68719476736 2^37 = 137438953472 2^38 = 274877906944 2^39 = 549755813888 2^40 = 1099511627776 --------------------------------------------------- Seen on a Debian 4.0 on an Athlon 64. The same occurs in DBD::SQLite2. Regards, Thomas
Fixed in SVN. Was a challenging one to fix! Thanks.