Bug 18084 – [REG2.072] tempCString buffer size is unittest-versioned

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-12-15T15:04:34Z
Last change time
2019-04-06T16:42:45Z
Keywords
pull
Assigned to
No Owner
Creator
anonymous4

Comments

Comment #0 by dfj1esp02 — 2017-12-15T15:04:34Z
tempCString code is suspicious: https://github.com/dlang/phobos/blob/master/std/internal/cstring.d#L221 If unittest-versioned function calls release-versioned tempCString, it will corrupt the stack, which depends on template emission strategy.
Comment #1 by schveiguy — 2017-12-15T20:43:57Z
drat. This was proper when it was first implemented here: https://github.com/dlang/phobos/pull/3415 But then messed up here: https://github.com/dlang/phobos/pull/4746 The original code was safe, unsure why it was undone... Will try to make a PR to restore the safe version.
Comment #2 by schveiguy — 2017-12-15T20:44:28Z
This isn't wrong-code, it's just a straight Phobos code bug.
Comment #3 by schveiguy — 2017-12-15T21:36:30Z
Comment #4 by dfj1esp02 — 2017-12-16T12:45:57Z
A variant of code: --- //field size doesn't depend on unittest version (to avoid corruption) //use `_buff` property to access the buffer To[256 / To.sizeof] _buffer; // the 'small string optimization' To[] _buff() { version (unittest) { // smaller size to trigger reallocations return _buffer[0..16/To.sizeof]; } else { return _buffer; // production size } } --- Also reallocation logic is quite smart.
Comment #5 by schveiguy — 2017-12-16T15:02:43Z
This is somewhat how the original worked. I have a feeling the compiler was having difficulty proving the return wasn't a piece of the object itself, which is why the latter PR was made.
Comment #6 by github-bugzilla — 2017-12-20T17:43:13Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/4873e2f6b3020c8edc18d4037d1f0d01a1ea6dd6 Fix issue 18084 - tempCString type should not change layout when used in unittests. https://github.com/dlang/phobos/commit/640df9fd9cc27bba1c5a0ff445f3383dfcd7e7d2 Merge pull request #5932 from schveiguy/fix18084 Fix issue 18084 - tempCString type should not change size when used in unittests.
Comment #7 by github-bugzilla — 2017-12-29T22:18:28Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/4873e2f6b3020c8edc18d4037d1f0d01a1ea6dd6 Fix issue 18084 - tempCString type should not change layout when used in https://github.com/dlang/phobos/commit/640df9fd9cc27bba1c5a0ff445f3383dfcd7e7d2 Merge pull request #5932 from schveiguy/fix18084
Comment #8 by dlang-bot — 2019-04-06T16:42:45Z
dlang/phobos pull request #6947 "[dmd-cxx] Backport Solaris and DragonflyBSD ports" was merged into dmd-cxx: - a181958b932a5761d7a8f7ab7a05736ce8e3e829 by Steven Schveighoffer: Fix issue 18084 - tempCString type should not change layout when used in unittests. https://github.com/dlang/phobos/pull/6947