summaryrefslogtreecommitdiff
path: root/extensions/source/logging
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-01-18 15:54:12 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-01-21 09:37:44 +0100
commit113536e974d7ebbbc484b0ef40406f9b4d14e511 (patch)
treed43dc6f98ec4fb2fb87df156260710d6fb0f8479 /extensions/source/logging
parent5e1e912010f35ee9ba5f387bdee82363d32a8105 (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 Change-Id: I82e9b08fa099546b2d6f29c702e1440df9e6c6e0 Reviewed-on: https://gerrit.libreoffice.org/66618 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'extensions/source/logging')
-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 6691ee17b060..2f5096ea510b 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", static_cast<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",
- static_cast<int>(_rRecord.LogTime.Year), static_cast<int>(_rRecord.LogTime.Month), static_cast<int>(_rRecord.LogTime.Day),
- static_cast<int>(_rRecord.LogTime.Hours), static_cast<int>(_rRecord.LogTime.Minutes), static_cast<int>(_rRecord.LogTime.Seconds), static_cast<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( " " );