From fa6f814eba13806725f87593ce583391e8d4dacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Borz=C3=AC?= Date: Fri, 4 Sep 2020 17:39:02 +0200 Subject: [PATCH] fix(Core/Misc): GCC warnings (#3428) --- src/common/Logging/Log.cpp | 8 +++++++- src/common/Utilities/Util.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp index 0740aeed8..669adc4dc 100644 --- a/src/common/Logging/Log.cpp +++ b/src/common/Logging/Log.cpp @@ -348,7 +348,13 @@ std::string Log::GetTimestampStr() // MM minutes (2 digits 00-59) // SS seconds (2 digits 00-59) char buf[20]; - snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec); + int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec); + + if (ret < 0) + { + return std::string("ERROR"); + } + return std::string(buf); } diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 6289d281d..4cc28e37d 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -235,7 +235,13 @@ std::string TimeToTimestampStr(time_t t) // MM minutes (2 digits 00-59) // SS seconds (2 digits 00-59) char buf[20]; - snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec); + int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec); + + if (ret < 0) + { + return std::string("ERROR"); + } + return std::string(buf); }