mirror of
https://github.com/fmtlib/fmt.git
synced 2024-10-02 04:52:03 +00:00
Workaround gcc stringop-overflow bug
This commit is contained in:
parent
524ca1c715
commit
7f157dca0a
@ -1295,23 +1295,23 @@ template <typename Char, typename UInt>
|
||||
FMT_CONSTEXPR20 auto format_decimal(Char* out, UInt value, int size)
|
||||
-> format_decimal_result<Char*> {
|
||||
FMT_ASSERT(size >= count_digits(value), "invalid digit count");
|
||||
out += size;
|
||||
Char* end = out;
|
||||
auto begin = out, end = out + size;
|
||||
unsigned n = to_unsigned(size);
|
||||
while (value >= 100) {
|
||||
// Integer division is slow so do it for a group of two digits instead
|
||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||
out -= 2;
|
||||
copy2(out, digits2(static_cast<size_t>(value % 100)));
|
||||
n -= 2;
|
||||
copy2(begin + n, digits2(static_cast<unsigned>(value % 100)));
|
||||
value /= 100;
|
||||
}
|
||||
if (value < 10) {
|
||||
*--out = static_cast<Char>('0' + value);
|
||||
return {out, end};
|
||||
if (value >= 10) {
|
||||
n -= 2;
|
||||
copy2(begin + n, digits2(static_cast<unsigned>(value)));
|
||||
} else {
|
||||
begin[--n] = static_cast<Char>('0' + value);
|
||||
}
|
||||
out -= 2;
|
||||
copy2(out, digits2(static_cast<size_t>(value)));
|
||||
return {out, end};
|
||||
return {begin + n, end};
|
||||
}
|
||||
|
||||
template <typename Char, typename UInt, typename Iterator,
|
||||
|
Loading…
Reference in New Issue
Block a user