D.gnu - [Bug 285] New: Backend optimizer assumes strings are null terminated.
- gdc-bugzilla gdcproject.org (32/33) Mar 11 2018 https://bugzilla.gdcproject.org/show_bug.cgi?id=285
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 gdcproject.org Reporter: ibuclaw gdcproject.orgFrom 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.
Mar 11 2018