extensions/source/logging/csvformatter.cxx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
New commits: commit 4634c5b49ffb770e97f369d2143565e8aca45b2f Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Tue Nov 30 12:42:21 2021 +0100 Commit: Pranam Lashkari <lpra...@collabora.com> CommitDate: Thu Oct 27 14:00:03 2022 +0200 Improve an snprintf printing css::util::DateTime members ...to avoid GCC 12 trunk > extensions/source/logging/csvformatter.cxx: In member function ‘virtual rtl::OUString logging::{anonymous}::CsvFormatter::format(const com::sun::star::logging::LogRecord&)’: > extensions/source/logging/csvformatter.cxx:241:70: error: ‘%02i’ directive output may be truncated writing between 2 and 5 bytes into a region of size between 0 and 14 [-Werror=format-truncation=] > 241 | snprintf( buffer, buffer_size, "%04i-%02i-%02iT%02i:%02i:%02i.%09i", > | ^~~~ > extensions/source/logging/csvformatter.cxx:241:44: note: directive argument in the range [0, 65535] > 241 | snprintf( buffer, buffer_size, "%04i-%02i-%02iT%02i:%02i:%02i.%09i", > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > extensions/source/logging/csvformatter.cxx:241:44: note: using the range [-2147483648, 2147483647] for directive argument > extensions/source/logging/csvformatter.cxx:241:21: note: ‘snprintf’ output between 30 and 49 bytes into a destination of size 31 > 241 | snprintf( buffer, buffer_size, "%04i-%02i-%02iT%02i:%02i:%02i.%09i", > | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 242 | static_cast<int>(record.LogTime.Year), > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 243 | static_cast<int>(record.LogTime.Month), > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 244 | static_cast<int>(record.LogTime.Day), > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 245 | static_cast<int>(record.LogTime.Hours), > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 246 | static_cast<int>(record.LogTime.Minutes), > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 247 | static_cast<int>(record.LogTime.Seconds), > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 248 | static_cast<int>(record.LogTime.NanoSeconds) ); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Change-Id: I426fd6c54b69c7dcc2153167961295c3bc5cf91f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126116 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> (cherry picked from commit 33a7e65502857687e778444c9b55500b40b4df19) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141848 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Pranam Lashkari <lpra...@collabora.com> diff --git a/extensions/source/logging/csvformatter.cxx b/extensions/source/logging/csvformatter.cxx index 0d0ec6479c5e..8e749db42831 100644 --- a/extensions/source/logging/csvformatter.cxx +++ b/extensions/source/logging/csvformatter.cxx @@ -28,6 +28,8 @@ #include <cppuhelper/supportsservice.hxx> #include <rtl/ustrbuf.hxx> +#include <sal/macros.h> +#include <sal/types.h> #include <stdio.h> #include <string_view> @@ -236,16 +238,16 @@ namespace logging } // ISO 8601 - char buffer[ 31 ]; + char buffer[ SAL_N_ELEMENTS("-32768-65535-65535T65535:65535:65535.4294967295") ]; const size_t buffer_size = sizeof( buffer ); - snprintf( buffer, buffer_size, "%04i-%02i-%02iT%02i:%02i:%02i.%09i", + snprintf( buffer, buffer_size, "%04i-%02u-%02uT%02u:%02u:%02u.%09" SAL_PRIuUINT32, static_cast<int>(record.LogTime.Year), - static_cast<int>(record.LogTime.Month), - static_cast<int>(record.LogTime.Day), - static_cast<int>(record.LogTime.Hours), - static_cast<int>(record.LogTime.Minutes), - static_cast<int>(record.LogTime.Seconds), - static_cast<int>(record.LogTime.NanoSeconds) ); + static_cast<unsigned int>(record.LogTime.Month), + static_cast<unsigned int>(record.LogTime.Day), + static_cast<unsigned int>(record.LogTime.Hours), + static_cast<unsigned int>(record.LogTime.Minutes), + static_cast<unsigned int>(record.LogTime.Seconds), + record.LogTime.NanoSeconds ); aLogEntry.appendAscii( buffer ); aLogEntry.append(comma_char); }