Comment #0 by bearophile_hugs — 2014-07-08T09:16:58Z
Tagged this as major, but it's borderline critical.
Found by "Archibald" and "anonymous" on NG D.learn:
http://forum.dlang.org/thread/[email protected]
void main() {
uint x = 0x22_DF_FF_FF;
uint y = 0xA2_DF_FF_FF;
assert(!(x < y && y < x)); // OK.
uint[] a = [x];
uint[] b = [y];
assert(!(a < b && b < a)); // Fails.
uint[1] a1 = [x];
uint[1] b1 = [y];
assert(!(a1 < b1 && b1 < a1)); // Fails.
}
Comment #1 by k.hara.pg — 2014-07-08T14:10:21Z
This is druntime issue.
From druntime/src/rt/typeinfo/ti_Aint.d
class TypeInfo_Ak : TypeInfo_Ai
{
override string toString() const { return "uint[]"; }
override int compare(in void* p1, in void* p2) const
{
uint[] s1 = *cast(uint[]*)p1;
uint[] s2 = *cast(uint[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u]; // <----
if (result)
return result;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
}
override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(uint);
}
}
Comparison of int[] is also wrong; it uses subtraction, which is OK in terms of sign handling, but wrong because of possibility of overflow (e.g., int.max - int.min overflows and doesn't return a positive result).
Comment #4 by github-bugzilla — 2014-07-12T03:42:51Z