[Issue 6175] New: String corruption when passing static char arrays to std.conv
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jun 18 10:23:45 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6175
Summary: String corruption when passing static char arrays to
std.conv
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Severity: major
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-06-18 10:18:57 PDT ---
This is fairly odd behavior:
Case 1:
char[9] statCArr = "blablabla";
auto res1 = to!(char[])(statCArr);
writeln(res1); // writes M @
writeln(statCArr[]); // writes blablabla
Case 2:
char[9] statCArr = "blablabla";
auto res1 = to!(char[])(statCArr);
writeln(res1); // writes L @
writeln(statCArr); // writes blablabla
Note: I've only removed the square brackets and this somehow ends up changing
the garbage value of res1. You can add random writeln() statements before the
call to std.conv.to and res would get different results.
If you reduce the character count then you get a compile time error:
char[6] statCArr = "blabla";
auto res2 = to!(char[])(statCArr);
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(99): Error: template
std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) &&
isInputRange!(Unqual!(S)) &&
isSomeChar!(ElementType!(S))) toImpl(T,S) if (!implicitlyConverts!(S,T) &&
isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S)))
matches more than one
template declaration,
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(231):toImpl(T,S) if
(isStaticArray!(S)) and
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(566):toImpl(Target,Source)
if (implicitlyConverts!(Source,Target))
So std.conv.to is pretty buggy for static arrays..
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list