summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-01-18 15:54:12 +0100
committerAron Budea <aron.budea@collabora.com>2019-02-06 02:42:19 +0100
commit2c652561e7637d662f94157259fddcd666984751 (patch)
tree22c556b5c6f072a5059ac43a9bdd585f43eb5945 /extensions
parentf98689833179403ac5ed3db8e1ce1db1a64fbe7e (diff)
Avoid -Werror=format-{overflow,truncation}=
...as emitted by at least GCC 8.2 with --enable-optimized, by making the buffers large enough for the (hypothetical) largest values of the various date/time components Reviewed-on: https://gerrit.libreoffice.org/66618 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com> (cherry picked from commit 113536e974d7ebbbc484b0ef40406f9b4d14e511) Change-Id: I82e9b08fa099546b2d6f29c702e1440df9e6c6e0
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/logging/plaintextformatter.cxx9
1 files changed, 5 insertions, 4 deletions
diff --git a/extensions/source/logging/plaintextformatter.cxx b/extensions/source/logging/plaintextformatter.cxx
index 40c7c7156c06..8514d52565ce 100644
--- a/extensions/source/logging/plaintextformatter.cxx
+++ b/extensions/source/logging/plaintextformatter.cxx
@@ -79,7 +79,8 @@ namespace logging
OUString SAL_CALL PlainTextFormatter::format( const LogRecord& _rRecord )
{
- char buffer[ 30 ];
+ char buffer[ sizeof("-32768-65535-65535 65535:65535:65535.4294967295") ];
+ // reserve enough space for hypothetical max length
const int buffer_size = sizeof( buffer );
int used = snprintf( buffer, buffer_size, "%10i", (int)_rRecord.SequenceNumber );
if ( used >= buffer_size || used < 0 )
@@ -94,9 +95,9 @@ namespace logging
aLogEntry.appendAscii( buffer );
aLogEntry.append( " " );
- snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%09i",
- (int)_rRecord.LogTime.Year, (int)_rRecord.LogTime.Month, (int)_rRecord.LogTime.Day,
- (int)_rRecord.LogTime.Hours, (int)_rRecord.LogTime.Minutes, (int)_rRecord.LogTime.Seconds, (int)_rRecord.LogTime.NanoSeconds );
+ snprintf( buffer, buffer_size, "%04" SAL_PRIdINT32 "-%02" SAL_PRIuUINT32 "-%02" SAL_PRIuUINT32 " %02" SAL_PRIuUINT32 ":%02" SAL_PRIuUINT32 ":%02" SAL_PRIuUINT32 ".%09" SAL_PRIuUINT32,
+ static_cast<sal_Int32>(_rRecord.LogTime.Year), static_cast<sal_uInt32>(_rRecord.LogTime.Month), static_cast<sal_uInt32>(_rRecord.LogTime.Day),
+ static_cast<sal_uInt32>(_rRecord.LogTime.Hours), static_cast<sal_uInt32>(_rRecord.LogTime.Minutes), static_cast<sal_uInt32>(_rRecord.LogTime.Seconds), _rRecord.LogTime.NanoSeconds );
aLogEntry.appendAscii( buffer );
aLogEntry.append( " " );