www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8830] New: [CTFE] Incorrect slicing with pointer from sliced array

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

           Summary: [CTFE] Incorrect slicing with pointer from sliced
                    array
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com



Minimal test case:

//----
import std.stdio;

string[] foo(string s)
{
  auto ss = s[1..$];
  auto l = ss.length;
  string s2 = ss.ptr[0..2];
  return [ss, s2];

}

void main()
{
  enum bar = foo("hello");
  writeln(bar);
}
//----

Creates:

//----
[
  "ello", //Sliced 1..$ of "hello"
  "hel"   // *should* be "ello"[0..2], but is actually "hello"[0..2]
]
//----

It would appear that when slicing a pointer extracted from a previously sliced,
array, it will slice from the first index of that *original* array.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 16 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8830





 Minimal test case:
 
 //----
 import std.stdio;
 
 string[] foo(string s)
 {
   auto ss = s[1..$];
   auto l = ss.length;
   string s2 = ss.ptr[0..2];
   return [ss, s2];
 
 }
 
 void main()
 {
   enum bar = foo("hello");
   writeln(bar);
 }
 //----
 
 Creates:
 
 //----
 [
   "ello", //Sliced 1..$ of "hello"
   "hel"   // *should* be "ello"[0..2], but is actually "hello"[0..2]
 ]
 //----
 
 It would appear that when slicing a pointer extracted from a previously sliced,
 array, it will slice from the first index of that *original* array.
What is strange though, is that ss.ptr *does* point to the right element: //---- string[] foo(string s) { auto ss = s[1..$]; auto l = ss.length; string s2 = [*ss.ptr]; return [ss, s2]; } void main() { enum bar = foo("hello"); writeln(bar); } //---- [ "ello", "e" //extracted pointer points to the right element. ] //---- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 16 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8830




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/abe37596dcfd0a150b86f703b582cfcf495c1727
Fix issue 8830 [CTFE] Incorrect slicing with pointer from sliced array

Simple bug -- the offset of the pointer needs to be added to the slice.

https://github.com/D-Programming-Language/dmd/commit/be5cae498f81c1e5965fd7755f432ffb7fdb5ec1
Minor code cleanup following bug 8830

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 20 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8830


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
            Version|unspecified                 |D1 & D2
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 20 2012