[Bug 91] String literals not always properly zero-terminated

via D.gnu d.gnu at puremagic.com
Sun Oct 26 06:20:18 PDT 2014


Peter Remmers <p.remmers at arcor.de> changed:

           What    |Removed                     |Added
                 CC|                            |p.remmers at arcor.de

--- Comment #6 from Peter Remmers <p.remmers at arcor.de> ---
I must add that I also just stumbled upon this. I was about to file another bug
but then found this.

I think string literals should always be zero terminated, not just when used as
a parameter to a function that takes a char*.

Here is a quote from std/string.d (the toStringz() function):

     * Note that the compiler will put a 0 past the end of static
     * strings, and the storage allocator will put a 0 past the end
     * of newly allocated char[]'s.

This little test program works on DMD and LDC2, but fails on GDC:

int main(string[] argv)
    string s = "Hello"; // same with static string s = "Hello";
    assert(*(s.ptr + s.length - 1) == 'o'); // OK
    assert(*(s.ptr + s.length) == '\0');    // fails

    return 0;

I think it's a bug.

You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20141026/ed177da0/attachment.html>

More information about the D.gnu mailing list