summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-01-18 15:54:12 +0100
committerAndras Timar <andras.timar@collabora.com>2019-10-06 18:56:07 +0200
commit297263e0cc5aa4b2b66fdc3fd17a725b9bc5fa42 (patch)
tree343db814deac95588517057689b985529379c365 /connectivity
parent444fccfc46554671c8c403b6b4ab74fa739dc9e6 (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 'connectivity')
-rw-r--r--connectivity/source/drivers/dbase/DTable.cxx13
-rw-r--r--connectivity/source/drivers/jdbc/ConnectionLog.cxx9
2 files changed, 12 insertions, 10 deletions
diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx
index 9e961cf793cb..535afd6660fe 100644
--- a/connectivity/source/drivers/dbase/DTable.cxx
+++ b/connectivity/source/drivers/dbase/DTable.cxx
@@ -1823,16 +1823,17 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo
aDate = ::dbtools::DBTypeConversion::toDate(thisColVal.getDouble());
else
aDate = thisColVal;
- char s[9];
+ char s[sizeof("-327686553565535")];
+ // reserve enough space for hypothetical max length
snprintf(s,
sizeof(s),
"%04d%02d%02d",
- static_cast<int>(aDate.Year),
- static_cast<int>(aDate.Month),
- static_cast<int>(aDate.Day));
+ static_cast<sal_Int32>(aDate.Year),
+ static_cast<sal_uInt32>(aDate.Month),
+ static_cast<sal_uInt32>(aDate.Day));
- // Exactly 8 bytes to copy:
- strncpy(pData,s,sizeof s - 1);
+ // Exactly 8 bytes to copy (even if s could hypothetically be longer):
+ memcpy(pData,s,8);
} break;
case DataType::INTEGER:
{
diff --git a/connectivity/source/drivers/jdbc/ConnectionLog.cxx b/connectivity/source/drivers/jdbc/ConnectionLog.cxx
index 329a0c185970..4f564c3fba6e 100644
--- a/connectivity/source/drivers/jdbc/ConnectionLog.cxx
+++ b/connectivity/source/drivers/jdbc/ConnectionLog.cxx
@@ -98,11 +98,12 @@ namespace comphelper { namespace log { namespace convert
OUString convertLogArgToString( const DateTime& _rDateTime )
{
- char buffer[ 30 ];
+ char buffer[ sizeof("-32768-65535-65535 65535:65535:65535.4294967295") ];
+ // reserve enough space for hypothetical max length
const size_t buffer_size = sizeof( buffer );
- snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%09i",
- static_cast<int>(_rDateTime.Year), static_cast<int>(_rDateTime.Month), static_cast<int>(_rDateTime.Day),
- static_cast<int>(_rDateTime.Hours), static_cast<int>(_rDateTime.Minutes), static_cast<int>(_rDateTime.Seconds), static_cast<int>(_rDateTime.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>(_rDateTime.Year), static_cast<sal_uInt32>(_rDateTime.Month), static_cast<sal_uInt32>(_rDateTime.Day),
+ static_cast<sal_uInt32>(_rDateTime.Hours), static_cast<sal_uInt32>(_rDateTime.Minutes), static_cast<sal_uInt32>(_rDateTime.Seconds), _rDateTime.NanoSeconds );
return OUString::createFromAscii( buffer );
}