Skip to content

Commit 5d4c57b

Browse files
author
cmiller@zippy.cornsilk.net
committed
Bug#19955: unsigned bigint used as signed with MOD function
Problem: When we have a really large number (between 2^63 and 2^64) as the left side of the mod operator, it gets improperly corerced into a signed value. Solution: Added check to see if the "negative" number is really positive, and if so, cast it.
1 parent 2b3a69e commit 5d4c57b

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

mysql-test/r/bigint.result

+11
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,14 @@ select * from t1 where bigint_col='17666000000000000000';
341341
bigint_col
342342
17666000000000000000
343343
drop table t1;
344+
345+
bug 19955 -- mod is signed with bigint
346+
select cast(10000002383263201056 as unsigned) mod 50 as result;
347+
result
348+
6
349+
create table t1 (c1 bigint unsigned);
350+
insert into t1 values (10000002383263201056);
351+
select c1 mod 50 as result from t1;
352+
result
353+
6
354+
drop table t1;

mysql-test/t/bigint.test

+9
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,13 @@ select * from t1 where bigint_col=17666000000000000000;
278278
select * from t1 where bigint_col='17666000000000000000';
279279
drop table t1;
280280

281+
--echo
282+
--echo bug 19955 -- mod is signed with bigint
283+
284+
select cast(10000002383263201056 as unsigned) mod 50 as result;
285+
286+
create table t1 (c1 bigint unsigned);
287+
insert into t1 values (10000002383263201056);
288+
select c1 mod 50 as result from t1;
289+
drop table t1;
281290

sql/item_func.cc

+4
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,10 @@ longlong Item_func_mod::int_op()
13261326
signal_divide_by_null();
13271327
return 0;
13281328
}
1329+
1330+
if (args[0]->unsigned_flag)
1331+
return ((ulonglong) value) % val2;
1332+
13291333
return value % val2;
13301334
}
13311335

0 commit comments

Comments
 (0)