digitalmars.D.bugs - [Issue 627] New: Concatenation of strings to string arrays with ~ corrupts data
- d-bugmail puremagic.com (41/41) Dec 02 2006 http://d.puremagic.com/issues/show_bug.cgi?id=627
- d-bugmail puremagic.com (14/14) Jan 29 2007 http://d.puremagic.com/issues/show_bug.cgi?id=627
- d-bugmail puremagic.com (4/4) Feb 06 2007 http://d.puremagic.com/issues/show_bug.cgi?id=627
- d-bugmail puremagic.com (9/9) Jul 01 2007 http://d.puremagic.com/issues/show_bug.cgi?id=627
- d-bugmail puremagic.com (7/7) Jul 23 2007 http://d.puremagic.com/issues/show_bug.cgi?id=627
http://d.puremagic.com/issues/show_bug.cgi?id=627 Summary: Concatenation of strings to string arrays with ~ corrupts data Product: D Version: 0.175 Platform: PC OS/Version: Windows Status: NEW Keywords: wrong-code Severity: major Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: deewiant gmail.com void main() { // it works with integers int[] bar; assert ((bar ~ 1).length == bar.length + 1); // it works with integer arrays int[][] baz; assert ((baz ~ cast(int[])[1]).length == baz.length + 1); // but not with string arrays, be they char[], wchar[], or dchar[] char[][] foo; assert ((foo ~ cast(char[])"foo").length == foo.length + 1); // outputs 7303014 on my machine printf("%d\n", (foo ~ cast(char[])"foo")[0].length); // this works, though: assert ((foo ~ [cast(char[])"foo"]).length == foo.length + 1); // as does this: char[] qux; assert (([qux] ~ cast(char[])"foo").length == [qux].length + 1); // and it works with literals - presumably constant folded? assert (([cast(dchar[])"asdf"] ~ cast(dchar[])"foo").length == [cast(dchar[])"asdf"].length + 1); // ~= works char[][] quux; auto quuux = quux.dup; quuux ~= "foo"; assert (quuux.length == quux.length + 1); } --
Dec 02 2006
http://d.puremagic.com/issues/show_bug.cgi?id=627 //foo ~ cast(char[])"foo" 0x004020a9 6a08 push 08 0x004020ab ff358ce04000 push dword ptr [_TMP0+00000004 (0040e08c)] 0x004020b1 ff3588e04000 push dword ptr [_TMP0 (0040e088)] 0x004020b7 ff75dc push dword ptr [ebp-24] 0x004020ba ff75d8 push dword ptr [foo] 0x004020bd e8e6070000 call __d_arraycat (004028a8) extern (C) byte[] _d_arraycat(byte[] x, byte[] y, size_t size) The "08" is the size of the data to be appended, char[].sizeof Apparently, the AA is being treated as a normal array. --
Jan 29 2007
http://d.puremagic.com/issues/show_bug.cgi?id=627 (Wait, there's no AA. What was I thinking? Sorry 'bout that.) --
Feb 06 2007
http://d.puremagic.com/issues/show_bug.cgi?id=627 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED Fixed DMD 1.018 and DMD 2.002 --
Jul 01 2007
http://d.puremagic.com/issues/show_bug.cgi?id=627 Added to DStress as http://dstress.kuehne.cn/run/o/opCat_27_A.d http://dstress.kuehne.cn/run/o/opCat_27_B.d http://dstress.kuehne.cn/run/o/opCat_27_C.d --
Jul 23 2007