mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-30 22:29:23 +01:00
Prevent silent data loss
This commit is contained in:
@@ -2778,6 +2778,11 @@ void check_format_string(S format_str) {
|
||||
ignore_unused(error);
|
||||
}
|
||||
|
||||
// Report truncation to prevent silent data loss.
|
||||
inline void report_truncation(bool truncated) {
|
||||
if (truncated) report_error("output is truncated");
|
||||
}
|
||||
|
||||
// Use vformat_args and avoid type_identity to keep symbols short and workaround
|
||||
// a GCC <= 4.8 bug.
|
||||
template <typename Char = char> struct vformat_args {
|
||||
@@ -2957,9 +2962,16 @@ struct format_to_result {
|
||||
/// Specifies if the output was truncated.
|
||||
bool truncated;
|
||||
|
||||
FMT_CONSTEXPR operator OutputIt&() & noexcept { return out; }
|
||||
FMT_CONSTEXPR operator const OutputIt&() const& noexcept { return out; }
|
||||
FMT_CONSTEXPR operator OutputIt&&() && noexcept {
|
||||
FMT_CONSTEXPR operator OutputIt&() & {
|
||||
detail::report_truncation(truncated);
|
||||
return out;
|
||||
}
|
||||
FMT_CONSTEXPR operator const OutputIt&() const& {
|
||||
detail::report_truncation(truncated);
|
||||
return out;
|
||||
}
|
||||
FMT_CONSTEXPR operator OutputIt&&() && {
|
||||
detail::report_truncation(truncated);
|
||||
return static_cast<OutputIt&&>(out);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user