[Bug 285] New: Backend optimizer assumes strings are null terminated.
gdc-bugzilla at gdcproject.org
gdc-bugzilla at gdcproject.org
Sun Mar 11 15:40:55 UTC 2018
https://bugzilla.gdcproject.org/show_bug.cgi?id=285
Bug ID: 285
Summary: Backend optimizer assumes strings are null terminated.
Product: GDC
Version: development
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: Normal
Component: gdc
Assignee: ibuclaw at gdcproject.org
Reporter: ibuclaw at gdcproject.org
>From phobos.
---
inout(char)[] fromStringz(inout(char)* cString) @nogc @system pure nothrow {
import core.stdc.string : strlen;
return cString ? cString[0 .. strlen(cString)] : null;
}
///
void main()
{
assert(fromStringz(null) == null);
assert(fromStringz("foo") == "foo");
}
---
Although gdc calls: build_string(3, "foo"), gcc itself still expects us to
factor in the null terminator into the length.
Because of this, when optimizing an inlined 'fromStringz', the result of
strlen("foo") is folded into the value '2', instead of the expected '3'.
--
You are receiving this mail because:
You are watching all bug changes.
More information about the D.gnu
mailing list