calc_filename buffer increase softened, exception is throw if buffer exceeds 4k, filename parameter renamed to match intend.

pull/2736/head
Bernd Ritter 2 years ago
parent 43711bc7fc
commit a361a751de

@ -46,12 +46,12 @@ struct daily_filename_calculator
*/ */
struct daily_filename_format_calculator struct daily_filename_format_calculator
{ {
static filename_t calc_filename(const filename_t &filename, const tm &now_tm) static filename_t calc_filename(const filename_t &filepath, const tm &now_tm)
{ {
// adapted from fmtlib: https://github.com/fmtlib/fmt/blob/8.0.1/include/fmt/chrono.h#L522-L546 // adapted from fmtlib: https://github.com/fmtlib/fmt/blob/8.0.1/include/fmt/chrono.h#L522-L546
filename_t tm_format; filename_t tm_format;
tm_format.append(filename); tm_format.append(filepath);
// By appending an extra space we can distinguish an empty result that // By appending an extra space we can distinguish an empty result that
// indicates insufficient buffer size from a guaranteed non-empty result // indicates insufficient buffer size from a guaranteed non-empty result
// https://github.com/fmtlib/fmt/issues/2238 // https://github.com/fmtlib/fmt/issues/2238
@ -69,7 +69,12 @@ struct daily_filename_format_calculator
buf.resize(count - 1); buf.resize(count - 1);
break; break;
} }
buf.resize(buf.size() * 2); buf.resize(buf.size() + 255);
if (buf.size() > 4096)
{
throw spdlog_ex("daily_file_sink: calc_filename() - strftime error or file name too big");
}
} }
return buf; return buf;

Loading…
Cancel
Save