Skip to content

Commit

Permalink
Merge pull request #6713 from FeepingCreature/fix/avoid-ludicrous-ove…
Browse files Browse the repository at this point in the history
…rallocation

Fix issue 19252: avoid ludicrous format length overestimate
  • Loading branch information
PetarKirov committed Sep 20, 2018
2 parents e80038b + c156f4a commit f12924e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion std/format.d
Expand Up @@ -6321,8 +6321,11 @@ private size_t guessLength(Char, S)(S fmtString)

if (spec.width == spec.precision)
len += spec.width;
else if (spec.width > 0 && (spec.precision == spec.UNSPECIFIED || spec.width > spec.precision))
else if (spec.width > 0 && spec.width != spec.DYNAMIC &&
(spec.precision == spec.UNSPECIFIED || spec.width > spec.precision))
{
len += spec.width;
}
else if (spec.precision != spec.UNSPECIFIED && spec.precision > spec.width)
len += spec.precision;
}
Expand All @@ -6345,6 +6348,7 @@ unittest
assert(guessLength!char("%2.4f") == 4);
assert(guessLength!char("%02d:%02d:%02d") == 8);
assert(guessLength!char("%0.2f") == 7);
assert(guessLength!char("%0*d") == 0);
}

/// ditto
Expand Down

0 comments on commit f12924e

Please sign in to comment.