summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMing Li <ming.5.li@here.com>2019-06-28 15:41:23 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-09-12 12:33:42 +0300
commit14d23a3a4b4c7c81e2cd382bb9291bacf5c4add3 (patch)
tree827aae51da6cafe03341aa7ebe65e4d4ed4a35f7
parentf0d3d459b8e2f19bf8eae923e2a01bcf57a4067f (diff)
downloadqtlocation-mapboxgl-14d23a3a4b4c7c81e2cd382bb9291bacf5c4add3.tar.gz
[core] Fix compilation failure caused by compilation warning for gcc 8
When compiling with gcc 8.3 under linux, I've got compiler error caused by the following warning: ../src/mbgl/util/chrono.cpp:26:26: error: ‘__builtin___snprintf_chk’ output may be truncated before the last format character [-Werror=format-truncation=] I need to slightly increase the buffer size to get rid of the warning.
-rw-r--r--src/mbgl/util/chrono.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/mbgl/util/chrono.cpp b/src/mbgl/util/chrono.cpp
index 6674e73c42..03e97eedf5 100644
--- a/src/mbgl/util/chrono.cpp
+++ b/src/mbgl/util/chrono.cpp
@@ -22,8 +22,13 @@ std::string rfc1123(Timestamp timestamp) {
std::time_t time = std::chrono::system_clock::to_time_t(timestamp);
std::tm info;
_gmtime(&time, &info);
- char buffer[30];
- snprintf(buffer, 30, "%s, %02d %s %4d %02d:%02d:%02d GMT", week[info.tm_wday], info.tm_mday,
+
+ // Buffer size 30 is OK assuming the year has 4 digits. However, In theory, it might have
+ // more digits. Under gcc 8.3.0 with -Os optimization flag, there is compiler warning
+ // complaining about the buffer size might be too small. Inceasing the buffer to 32 fixes
+ // the warning.
+ char buffer[32];
+ snprintf(buffer, 32, "%s, %02d %s %4d %02d:%02d:%02d GMT", week[info.tm_wday], info.tm_mday,
months[info.tm_mon], 1900 + info.tm_year, info.tm_hour, info.tm_min, info.tm_sec);
return buffer;
}