-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.4.4
-
Component/s: Build
-
Fully Compatible
-
ALL
MongoDB fails to build with gcc 7. The following warning is issued:
src/mongo/util/time_support.cpp: In function 'void mongo::
{anonymous}::_dateToCtimeString(mongo::Date_t, mongo::{anonymous}::DateStringBuffer*)':
src/mongo/util/time_support.cpp:196:6: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
void _dateToCtimeString(Date_t date, DateStringBuffer* result) {
^~~~~~~~~~~~~~~~~~
src/mongo/util/time_support.cpp:206:13: note: 'snprintf' output between 5 and 6 bytes into a destination of size 5
snprintf(
milliSecStr, millisSubstrLen + 1, ".%03d", static_cast<int32_t>(date.asInt64() % 1000));
The issue seems to be that gcc sees that int32_t can be negative (really, why time since epoch can't be negative here?). In this case 5 symbols can be not enough to store string in .%03d format.