www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10948] New: BitArray.opEquals is invalid

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10948

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



---
Created an attachment (id=1245)
diff with git master

Invalid calculation n value:
-        auto n = this.length / bitsPerSizeT;
+        auto n = (this.length + (bitsPerSizeT - 1)) / bitsPerSizeT;


Test:
//                  0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5
6 7
static bool[] bf =
[1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
static bool[] bg =
[1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];

BitArray f; f.init(bf);
BitArray g; g.init(bg);
assert(f != g);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 01 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10948




---
Sorry. It is hasty fix.

Real problem - it is 

size_t mask = (1 << n) - 1;

On 64 bit system size_t has 64 bits.
Byt 1 on this expression it is not size_t, it it 32 bit integer.
And (1 << 32) return 0;

Good fix is

size_t mask = (cast(size_t)1 << n) - 1;


I see this problem on other methods:
- opCmp:
size_t mask = cast(size_t)(1 << j);
must be replaced by
size_t mask = (cast(size_t)1 << j);

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