Thread overview
[Issue 13073] Wrong uint array comparison
Jul 08, 2014
Kenji Hara
[Issue 13073] Wrong uint/int array comparison
July 08, 2014
https://issues.dlang.org/show_bug.cgi?id=13073

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |wrong-code
          Component|DMD                         |druntime
           Hardware|x86                         |All
                 OS|Windows                     |All

--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> ---
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);
    }
}

--
July 08, 2014
https://issues.dlang.org/show_bug.cgi?id=13073

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--
July 11, 2014
https://issues.dlang.org/show_bug.cgi?id=13073

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #2 from hsteoh@quickfur.ath.cx ---
https://github.com/D-Programming-Language/druntime/pull/881

--
July 12, 2014
https://issues.dlang.org/show_bug.cgi?id=13073

--- Comment #3 from hsteoh@quickfur.ath.cx ---
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).

--
July 12, 2014
https://issues.dlang.org/show_bug.cgi?id=13073

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Wrong uint array comparison |Wrong uint/int array
                   |                            |comparison

--
July 12, 2014
https://issues.dlang.org/show_bug.cgi?id=13073

--- Comment #4 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/edbcce94acaa10fa0137bcec99f095a8e7c0ed8f Add unittest for issue 13073.

https://github.com/D-Programming-Language/druntime/commit/b0920b65de2ff5c9b777642fc438691a59f63611 Merge pull request #881 from quickfur/issue13073

Fix wrong comparison of uint[]/int[] due to invalid subtraction.

--
July 12, 2014
https://issues.dlang.org/show_bug.cgi?id=13073

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from hsteoh@quickfur.ath.cx ---
Confirmed fixed in git HEAD.

--