From 4873e2f6b3020c8edc18d4037d1f0d01a1ea6dd6 Mon Sep 17 00:00:00 2001 From: Steven Schveighoffer Date: Tue, 19 Dec 2017 11:55:08 -0500 Subject: [PATCH] Fix issue 18084 - tempCString type should not change layout when used in unittests. --- std/internal/cstring.d | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/std/internal/cstring.d b/std/internal/cstring.d index 776e1f2e563..76e169557d4 100644 --- a/std/internal/cstring.d +++ b/std/internal/cstring.d @@ -218,17 +218,20 @@ private: To* _ptr; size_t _length; // length of the string + + // the 'small string optimization' version (unittest) { - enum buffLength = 16 / To.sizeof; // smaller size to trigger reallocations + // smaller size to trigger reallocations. Padding is to account for + // unittest/non-unittest cross-compilation (to avoid corruption) + To[16 / To.sizeof] _buff; + To[(256 - 16) / To.sizeof] _unittest_pad; } else { - enum buffLength = 256 / To.sizeof; // production size + To[256 / To.sizeof] _buff; // production size } - To[buffLength] _buff; // the 'small string optimization' - static TempCStringBuffer trustedVoidInit() { TempCStringBuffer res = void; return res; } }