From 32fa5ec0542bdcd8db1848b3fd72fb4b707ef78d Mon Sep 17 00:00:00 2001 From: Odysseas Georgoudis Date: Fri, 17 May 2024 21:33:42 +0100 Subject: [PATCH] Fix fold expression argument evaluation --- CHANGELOG.md | 1 + quill/include/quill/detail/Serialize.h | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d5b5b5b..704043b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ - Fix bug in `TransitEvent` when dynamic log level is used ([#427](https://github.com/odygrd/quill/pull/427)) - Fix build error for Intel compiler classic ([#414](https://github.com/odygrd/quill/pull/414)) - Added `JsonConsoleHandler` ([#413](https://github.com/odygrd/quill/issues/413)) +- Fix fold expression argument evaluation. This bug could occur when logging c style strings ## v3.8.0 diff --git a/quill/include/quill/detail/Serialize.h b/quill/include/quill/detail/Serialize.h index 663358bc..dea29b2d 100644 --- a/quill/include/quill/detail/Serialize.h +++ b/quill/include/quill/detail/Serialize.h @@ -277,8 +277,12 @@ template QUILL_NODISCARD QUILL_ATTRIBUTE_HOT inline size_t calculate_args_size_and_populate_string_lengths( QUILL_MAYBE_UNUSED size_t* c_style_string_lengths, Args const&... args) noexcept { + // Do not use a fold expression for sequential evaluation QUILL_MAYBE_UNUSED uint32_t c_style_string_lengths_index{0}; - return (0u + ... + calculate_arg_size_and_string_length(c_style_string_lengths, c_style_string_lengths_index, args)); + size_t total_size{0}; + ((total_size += calculate_arg_size_and_string_length(c_style_string_lengths, c_style_string_lengths_index, args)), + ...); + return total_size; } /**