What do you think of this piece of C code?
void foo(long v) {
unsigned long u;
unsigned sign;
if (v < 0) {
u = -v;
sign = 1;
} else {
u = v;
sign = 0;
}
...
Seems pretty simple, right? Then what do you think of this output from MySQL:
mysql> create table t1 (a bigint) as select '-9223372036854775807.5' as a; mysql> select * from t1; +----------------------+ | a | +----------------------+ | -'..--).0-*(+,))+(0( | +----------------------+Yes, that is authentic output from older versions of MySQL. Not just the wrong number, the output is complete garbage! This is my all-time favorite MySQL bug#31799. It was caused by code like the above C snippet.
So can you spot what is wrong with the code? Looks pretty simple, does it
[Read more...]