Skip to content

Commit c847733

Browse files
authored
Fix LGTM localtime function warnings (sonic-net#707)
Signed-off-by: kcudnik <[email protected]>
1 parent 9fb6fe9 commit c847733

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

lib/src/Recorder.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#include "swss/table.h"
2-
#include <vector>
3-
#include <fstream>
4-
51
#include "Recorder.h"
62

73
#include "meta/sai_serialize.h"
@@ -11,6 +7,8 @@
117
#include <inttypes.h>
128

139
#include <cstring>
10+
#include <vector>
11+
#include <fstream>
1412

1513
using namespace sairedis;
1614
using namespace saimeta;
@@ -216,7 +214,10 @@ std::string Recorder::getTimestamp()
216214

217215
gettimeofday(&tv, NULL);
218216

219-
size_t size = strftime(buffer, 32, "%Y-%m-%d.%T.", localtime(&tv.tv_sec));
217+
struct tm now;
218+
localtime_r(&tv.tv_sec, &now);
219+
220+
size_t size = strftime(buffer, 32, "%Y-%m-%d.%T.", &now);
220221

221222
snprintf(&buffer[size], 32, "%06ld", tv.tv_usec);
222223

@@ -283,7 +284,6 @@ void Recorder::recordQueryAttributeCapabilityResponse(
283284
recordLine("Q|attribute_capability|" + sai_serialize_status(status) + "|" + joinFieldValues(arguments));
284285
}
285286

286-
287287
void Recorder::recordQueryAttributeEnumValuesCapability(
288288
_In_ const std::string& key,
289289
_In_ const std::vector<swss::FieldValueTuple>& arguments)
@@ -514,7 +514,6 @@ void Recorder::recordBulkGenericSet(
514514
recordLine("S|" + key + joined);
515515
}
516516

517-
518517
void Recorder::recordBulkGenericSetResponse(
519518
_In_ sai_status_t status,
520519
_In_ uint32_t objectCount,
@@ -833,7 +832,6 @@ void Recorder::recordRemove( \
833832
_X(ROUTE_ENTRY,route_entry); \
834833
_X(NAT_ENTRY,nat_entry); \
835834

836-
837835
REDIS_DECLARE_EVERY_ENTRY(DECLARE_RECORD_REMOVE_ENTRY)
838836

839837
#define DECLARE_RECORD_CREATE_ENTRY(OT,ot) \
@@ -940,7 +938,6 @@ void Recorder::recordQueryAttributeCapability(
940938
recordQueryAttributeCapability(key, values);
941939
}
942940

943-
944941
void Recorder::recordQueryAttributeCapabilityResponse(
945942
_In_ sai_status_t status,
946943
_In_ sai_object_type_t objectType,

saisdkdump/saisdkdump.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ int main(int argc, char **argv)
111111
{
112112
std::ostringstream strStream;
113113
time_t t = time(NULL);
114-
struct tm *now = localtime(&t);
114+
struct tm local_tm;
115+
struct tm *now = localtime_r(&t, &local_tm);
115116
strStream << "/tmp/saisdkdump_" << now->tm_mday << "_" << now->tm_mon + 1 << "_" << now->tm_year + 1900 << "_" << now->tm_hour << "_" << now->tm_min << "_" << now->tm_sec;
116117
fileName = strStream.str();
117118
SWSS_LOG_INFO("The dump file is not specified, generated \"%s\" file name", fileName.c_str());

syncd/PortMapParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <sstream>
88
#include <cstring>
99

10-
// FIXME: introduce common config format for SONiC
10+
// TODO: introduce common config format for SONiC
1111
std::shared_ptr<PortMap> PortMapParser::parsePortMap(
1212
_In_ const std::string& portMapFile)
1313
{

0 commit comments

Comments
 (0)