Skip to content

Commit c48c0e7

Browse files
authored
Fix unsigned int overflow (#1530)
1 parent 0004702 commit c48c0e7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

‎driver_test.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,16 @@ func TestCRUD(t *testing.T){
388388
funcTestNumbersToAny(t*testing.T){
389389
runTestsParallel(t, dsn, func(dbt*DBTest, tblstring){
390390
dbt.mustExec("CREATE TABLE "+tbl+" (id INT PRIMARY KEY, b BOOL, i8 TINYINT, "+
391-
"i16 SMALLINT, i32 INT, i64 BIGINT, f32 FLOAT, f64 DOUBLE)")
392-
dbt.mustExec("INSERT INTO "+tbl+" VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5)")
391+
"i16 SMALLINT, i32 INT, i64 BIGINT, f32 FLOAT, f64 DOUBLE, iu32 INT UNSIGNED)")
392+
dbt.mustExec("INSERT INTO "+tbl+" VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5, 4294967295)")
393393

394-
// Use binaryRows for intarpolateParams=false and textRows for intarpolateParams=true.
395-
rows:=dbt.mustQuery("SELECT b, i8, i16, i32, i64, f32, f64 FROM "+tbl+" WHERE id=?", 1)
394+
// Use binaryRows for interpolateParams=false and textRows for interpolateParams=true.
395+
rows:=dbt.mustQuery("SELECT b, i8, i16, i32, i64, f32, f64, iu32 FROM "+tbl+" WHERE id=?", 1)
396396
if!rows.Next(){
397397
dbt.Fatal("no data")
398398
}
399-
varb, i8, i16, i32, i64, f32, f64any
400-
err:=rows.Scan(&b, &i8, &i16, &i32, &i64, &f32, &f64)
399+
varb, i8, i16, i32, i64, f32, f64, iu32any
400+
err:=rows.Scan(&b, &i8, &i16, &i32, &i64, &f32, &f64, &iu32)
401401
iferr!=nil{
402402
dbt.Fatal(err)
403403
}
@@ -422,6 +422,9 @@ func TestNumbersToAny(t *testing.T){
422422
iff64.(float64) !=2.5{
423423
dbt.Errorf("f64 != 2.5")
424424
}
425+
ifiu32.(int64) !=4294967295{
426+
dbt.Errorf("iu32 != 4294967295")
427+
}
425428
})
426429
}
427430

‎packets.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ func (rows *textRows) readRow(dest []driver.Value) error{
828828
}
829829

830830
casefieldTypeTiny, fieldTypeShort, fieldTypeInt24, fieldTypeYear, fieldTypeLong:
831-
dest[i], err=strconv.ParseInt(string(buf), 10, 32)
831+
dest[i], err=strconv.ParseInt(string(buf), 10, 64)
832832

833833
casefieldTypeLongLong:
834834
ifrows.rs.columns[i].flags&flagUnsigned!=0{

0 commit comments

Comments
(0)