www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1219] New: long.max.stringof gets corrupted

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1219

           Summary: long.max.stringof gets corrupted
           Product: D
           Version: 1.014
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: fvbommel wxs.nl


See the comments for stuff that makes the problem go away:
---
import std.stdio;
import std.string;

// "Manually" instantiating this template function (changing it into
// a regular function with void[0] argument) makes the problem disappear.
void foo(T)(T t) {
    /*
    // It even fails if this is put in (so below code isn't reached).
    return null;
    //*/

    // It works if this is removed:
    static if (is(typeof(T.nonexistant)))
    {}
}

void main() {
    /*
    // Shows that long.max.stringof is wrong:
    writefln(long.max);
    writefln(long.max.stringof);
    //*/

    /*
    // Shows the problem more exactly:
    // (namely, the first 2 bytes of long.max.stringof are wrong)
    foreach(char c; format(long.max)) {
            writef("%02x ", c);
    }
    writefln();
    foreach(char c; long.max.stringof) {
            writef("%02x ", c);
    }
    writefln();
    //*/

    assert(long.max.stringof == format(long.max));      // fails

    // Remove this or change the argument to something
    // other than a static array and it works.
    foo([]);
}
---


-- 
May 07 2007
next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1219






Another interesting case, likely related:
---
import std.stdio;
import std.string;

void main() {
    writefln(long.max.stringof);
    writefln(ulong.max.stringof);
}
---
The first three bytes of long.max.stringof seem to be overwritten by "-1\0".
ulong.max.stringof is incorrectly displayed as "-1".
If you change the order, the first three characters of long.max.stringof
overwrite the characters of ulong.max.stringof (including the trailing \0).


-- 
May 07 2007
parent Don Clugston <dac nospam.com.au> writes:
d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1219
 
 
 
 
 

 Another interesting case, likely related:
 ---
 import std.stdio;
 import std.string;
 
 void main() {
     writefln(long.max.stringof);
     writefln(ulong.max.stringof);
 }
 ---
 The first three bytes of long.max.stringof seem to be overwritten by "-1\0".
 ulong.max.stringof is incorrectly displayed as "-1".
 If you change the order, the first three characters of long.max.stringof
 overwrite the characters of ulong.max.stringof (including the trailing \0).
I've seen similar things, and I think it is related to the ".". It can happen to floating-point numbers as well, when they contain a decimal point.
May 07 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1219


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed DMD 1.018 and DMD 2.002


-- 
Jul 01 2007