www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6079] New: [CTFE] Array index out of bound detection is off-by-one

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

           Summary: [CTFE] Array index out of bound detection is
                    off-by-one
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Keywords: accepts-invalid
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: kennytm gmail.com



Test case:

------------------------
static assert({
    int[] x = [1,2,3,4];
    x[4] = 1;
    return true;
}());
------------------------

In 2.052 this is correctly rejected, but in 2.053 this is wrongly accepted.
Changing the [4] to [5] will make the code fail to compile. There should be
some off-by-one error introduced between the two versions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6079




The bug was introduced in commit 4120b86*, I believe this is because of 

             if (indexToModify > destarraylen)
//                             ^ should be >=.

*:
https://github.com/D-Programming-Language/dmd/commit/4120b86f67eace7a7b930a6ceca823d2088deefd#L0R2728

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6079


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED



https://github.com/D-Programming-Language/dmd/commit/d96486ec09401bdd5cf64d037e024b8e687b8014

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 01 2011