mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 06:00:35 +03:00
Fix Issue 21256 - Segfault with Appender!string.init.toString()
This commit is contained in:
parent
10e862b458
commit
f3c8d75a9e
1 changed files with 13 additions and 2 deletions
15
std/array.d
15
std/array.d
|
@ -3619,17 +3619,18 @@ if (isDynamicArray!A)
|
||||||
|
|
||||||
auto app = appender!string();
|
auto app = appender!string();
|
||||||
auto spec = singleSpec("%s");
|
auto spec = singleSpec("%s");
|
||||||
|
immutable len = _data ? _data.arr.length : 0;
|
||||||
// different reserve lengths because each element in a
|
// different reserve lengths because each element in a
|
||||||
// non-string-like array uses two extra characters for `, `.
|
// non-string-like array uses two extra characters for `, `.
|
||||||
static if (isSomeString!A)
|
static if (isSomeString!A)
|
||||||
{
|
{
|
||||||
app.reserve(_data.arr.length + 25);
|
app.reserve(len + 25);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Multiplying by three is a very conservative estimate of
|
// Multiplying by three is a very conservative estimate of
|
||||||
// length, as it assumes each element is only one char
|
// length, as it assumes each element is only one char
|
||||||
app.reserve((_data.arr.length * 3) + 25);
|
app.reserve((len * 3) + 25);
|
||||||
}
|
}
|
||||||
toString(app, spec);
|
toString(app, spec);
|
||||||
return app.data;
|
return app.data;
|
||||||
|
@ -3773,6 +3774,16 @@ if (isDynamicArray!A)
|
||||||
assert(wstr.data == str.to!wstring);
|
assert(wstr.data == str.to!wstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://issues.dlang.org/show_bug.cgi?id=21256
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
Appender!string app1;
|
||||||
|
app1.toString();
|
||||||
|
|
||||||
|
Appender!(int[]) app2;
|
||||||
|
app2.toString();
|
||||||
|
}
|
||||||
|
|
||||||
//Calculates an efficient growth scheme based on the old capacity
|
//Calculates an efficient growth scheme based on the old capacity
|
||||||
//of data, and the minimum requested capacity.
|
//of data, and the minimum requested capacity.
|
||||||
//arg curLen: The current length
|
//arg curLen: The current length
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue