Thread overview
I hate ".dup"
Mar 23, 2009
Qian Xu
Mar 23, 2009
BCS
Mar 24, 2009
Qian Xu
Mar 24, 2009
Qian Xu
March 23, 2009
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
March 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)


March 23, 2009
On Mon, Mar 23, 2009 at 12:15 PM, BCS <none@anon.com> wrote:
> 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)

It is unique to DMD/Optlink.  GDC Win will produce EXEs that throw a segfault if you attempt to modify a read-only string.
March 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 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
March 24, 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.
> 
> -Steve

TimeStamp.iso8601(..) does not call the parse() function.


March 24, 2009
On Tue, 24 Mar 2009 12:26:29 -0400, Qian Xu <quian.xu@stud.tu-ilmenau.de> wrote:

> 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.
>>
>> -Steve
>
> TimeStamp.iso8601(..) does not call the parse() function.

The bug was in parseInt.  Please try it.

-Steve
March 24, 2009
Steven Schveighoffer wrote:
>> TimeStamp.iso8601(..) does not call the parse() function.
> 
> The bug was in parseInt.  Please try it.
> 

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.com