I hate ".dup"
Steven Schveighoffer
schveiguy at yahoo.com
Mon Mar 23 10:51:04 PDT 2009
On Mon, 23 Mar 2009 11:07:16 -0400, Qian Xu <quian.xu at 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 Xu
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.
-Steve
More information about the Digitalmars-d-learn
mailing list