www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11015] New: BitArray.opCom is invalid on 64 bit machines

http://d.puremagic.com/issues/show_bug.cgi?id=11015

           Summary: BitArray.opCom is invalid on 64 bit machines
           Product: D
           Version: unspecified
          Platform: x86_64
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: nikolay.v.belov gmail.com


--- Comment #0 from nbelov <nikolay.v.belov gmail.com> 2013-09-12 01:33:01 PDT
---
result.ptr[dim - 1] &= ~(~0 << (len & (bitsPerSizeT-1)));
On 64 bit machine 0 - is 32 bit value, but bitsPerSizeT == 64.

Need add cast 0 to size_t:
result.ptr[dim - 1] &= ~(~cast(size_t)0 << (len & (bitsPerSizeT-1)));


Test:
       foreach (len; 1 .. 256)
        {
            foreach (i; 0 .. len)
            {
                BitArray a1; a1.length = len;
                foreach (j; 0 .. len)
                {
                    a1[j] = true;
                }

                a1[i] = false;

                BitArray a2; a2.length = len;
                a2[i] = true;
                BitArray a3 = ~a2;

                assert(a3 == a1);
            }
        }

For reproduce you need fix opEquals (see bug #10948:
http://d.puremagic.com/issues/show_bug.cgi?id=10948)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 12 2013