summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-11-30 12:42:21 +0100
committerStephan Bergmann <sbergman@redhat.com>2021-11-30 16:11:49 +0100
commit33a7e65502857687e778444c9b55500b40b4df19 (patch)
treee79760a832e1c54281d0b489e2b441d8b2e1befa /extensions
parent9a681101543f9c60112dfc0d04309be7dc50b61d (diff)
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 <sbergman@redhat.com>
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/logging/csvformatter.cxx18
1 files changed, 10 insertions, 8 deletions
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);
}