digitalmars.D.learn - I hate ".dup"
- Qian Xu (27/27) Mar 23 2009 I have spent one day to find out an error.
- BCS (5/8) Mar 23 2009 Run it on linux and it will seg-v when you try to access a literal strin...
- Jarrett Billingsley (3/11) Mar 23 2009 It is unique to DMD/Optlink. GDC Win will produce EXEs that throw a
- Steven Schveighoffer (9/38) Mar 23 2009 Coincidentally, someone else discovered a buffer-overrun bug in
- Qian Xu (2/13) Mar 24 2009 TimeStamp.iso8601(..) does not call the parse() function.
- Steven Schveighoffer (4/17) Mar 24 2009 The bug was in parseInt. Please try it.
- Qian Xu (8/12) Mar 24 2009 It worth a try.
I have spent one day to find out an error. ----------------------------------------------------------------- class MyTime { this(char[] timestring) { Time t; int p = tango.time.TimeStamp.iso8601(timestring, t); //... } // other methods } unittest { MyTime mt = new MyTime("01:10:20,050"); assert(MyTime.addMillis(mt, 1).toString() == "01:10:20,051"); // sometimes failed } ----------------------------------------------------------------- I ran this unit-test together with some other tests. Sometimes no error, sometimes with errors. Finally I have added timestring.dup in constructor, the problem does not appear any more. Oh god. I have to add ".dup" at the end of every string to avoid potential program errors. This is so incredible.... Best regards Qian Xu
Mar 23 2009
Hello Qian,Oh god. I have to add ".dup" at the end of every string to avoid potential program errors. This is so incredible....Run it on linux and it will seg-v when you try to access a literal string. Oh, and that issue is in no way unique to D. Any language with mutable strings will have it and any language without will force the copies anyway (but with better syntax)
Mar 23 2009
On Mon, Mar 23, 2009 at 12:15 PM, BCS <none anon.com> wrote:Hello Qian,It is unique to DMD/Optlink. GDC Win will produce EXEs that throw a segfault if you attempt to modify a read-only string.Oh god. I have to add ".dup" at the end of every string to avoid potential program errors. This is so incredible....Run it on linux and it will seg-v when you try to access a literal string. Oh, and that issue is in no way unique to D. Any language with mutable strings will have it and any language without will force the copies anyway (but with better syntax)
Mar 23 2009
On Mon, 23 Mar 2009 11:07:16 -0400, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:I have spent one day to find out an error. ----------------------------------------------------------------- class MyTime { this(char[] timestring) { Time t; int p = tango.time.TimeStamp.iso8601(timestring, t); //... } // other methods } unittest { MyTime mt = new MyTime("01:10:20,050"); assert(MyTime.addMillis(mt, 1).toString() == "01:10:20,051"); // sometimes failed } ----------------------------------------------------------------- I ran this unit-test together with some other tests. Sometimes no error, sometimes with errors. Finally I have added timestring.dup in constructor, the problem does not appear any more. Oh god. I have to add ".dup" at the end of every string to avoid potential program errors. This is so incredible.... Best regards Qian XuCoincidentally, someone else discovered a buffer-overrun bug in tango.text.convert.TimeStamp, see http://www.dsource.org/projects/tango/forums/topic/704 Please try downloading the latest trunk code and see if your code still fails. You should not have to .dup the string, if you do, that is a bug. -Steve
Mar 23 2009
Steven Schveighoffer wrote:Coincidentally, someone else discovered a buffer-overrun bug in tango.text.convert.TimeStamp, see http://www.dsource.org/projects/tango/forums/topic/704 Please try downloading the latest trunk code and see if your code still fails. You should not have to .dup the string, if you do, that is a bug. -SteveTimeStamp.iso8601(..) does not call the parse() function.
Mar 24 2009
On Tue, 24 Mar 2009 12:26:29 -0400, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:Steven Schveighoffer wrote:The bug was in parseInt. Please try it. -SteveCoincidentally, someone else discovered a buffer-overrun bug in tango.text.convert.TimeStamp, see http://www.dsource.org/projects/tango/forums/topic/704 Please try downloading the latest trunk code and see if your code still fails. You should not have to .dup the string, if you do, that is a bug. -SteveTimeStamp.iso8601(..) does not call the parse() function.
Mar 24 2009
Steven Schveighoffer wrote:It worth a try. I have added too many ".dup" in my code. I will confirm this ASAP. Thanks for your information ^^) -- Xu, Qian (stanleyxu) http://stanleyxu2005.blogspot.comTimeStamp.iso8601(..) does not call the parse() function.The bug was in parseInt. Please try it.
Mar 24 2009