From dc0f740a0453adac74c7dcc592e90d6bc81c001c Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Mon, 14 Aug 2023 17:52:59 +0000 Subject: [PATCH] Avoid copying timeval onto stack --- apps/backend/backend_client.c | 2 +- lib/src/clixon_netconf_monitoring.c | 6 +++--- lib/src/clixon_proc.c | 2 +- lib/src/clixon_stream.c | 4 ++-- util/clixon_util_stream.c | 10 ++++------ 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 54592f2ab..8281eb4bc 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -215,7 +215,7 @@ backend_monitoring_state_get(clicon_handle h, if (ce->ce_source_host) cprintf(cb, "%s", ce->ce_source_host); if (ce->ce_time.tv_sec != 0){ - if (time2str(ce->ce_time, timestr, sizeof(timestr)) < 0){ + if (time2str(&ce->ce_time, timestr, sizeof(timestr)) < 0){ clicon_err(OE_UNIX, errno, "time2str"); goto done; } diff --git a/lib/src/clixon_netconf_monitoring.c b/lib/src/clixon_netconf_monitoring.c index a3a165a74..aa22aabce 100644 --- a/lib/src/clixon_netconf_monitoring.c +++ b/lib/src/clixon_netconf_monitoring.c @@ -74,7 +74,7 @@ per_datastore(clicon_handle h, { int retval = -1; uint32_t sid; - struct timeval tv = {0,}; + struct timeval tv; char timestr[28]; cprintf(cb, "%s", db); @@ -83,7 +83,7 @@ per_datastore(clicon_handle h, cprintf(cb, ""); cprintf(cb, "%u", sid); xmldb_lock_timestamp(h, db, &tv); - if (time2str(tv, timestr, sizeof(timestr)) < 0){ + if (time2str(&tv, timestr, sizeof(timestr)) < 0){ clicon_err(OE_UNIX, errno, "time2str"); goto done; } @@ -321,7 +321,7 @@ netconf_monitoring_statistics_init(clicon_handle h) cvec *cvv = NULL; gettimeofday(&tv, NULL); - if (time2str(tv, timestr, sizeof(timestr)) < 0) + if (time2str(&tv, timestr, sizeof(timestr)) < 0) goto done; clicon_data_set(h, "netconf-start-time", timestr); /* RFC 6022 */ if ((cvv = cvec_new(0)) == NULL){ diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c index 31d9a1d8a..6bceeb11e 100644 --- a/lib/src/clixon_proc.c +++ b/lib/src/clixon_proc.c @@ -753,7 +753,7 @@ clixon_process_status(clicon_handle h, cprintf(cbret, "%s", CLIXON_LIB_NS, clicon_int2str(proc_state_map, pe->pe_state)); if (timerisset(&pe->pe_starttime)){ - if (time2str(pe->pe_starttime, timestr, sizeof(timestr)) < 0){ + if (time2str(&pe->pe_starttime, timestr, sizeof(timestr)) < 0){ clicon_err(OE_UNIX, errno, "time2str"); goto done; } diff --git a/lib/src/clixon_stream.c b/lib/src/clixon_stream.c index bcd5eb8af..cdd436e68 100644 --- a/lib/src/clixon_stream.c +++ b/lib/src/clixon_stream.c @@ -580,7 +580,7 @@ stream_notify(clicon_handle h, goto done; } gettimeofday(&tv, NULL); - if (time2str(tv, timestr, sizeof(timestr)) < 0){ + if (time2str(&tv, timestr, sizeof(timestr)) < 0){ clicon_err(OE_UNIX, errno, "time2str"); goto done; } @@ -645,7 +645,7 @@ stream_notify_xml(clicon_handle h, goto done; } gettimeofday(&tv, NULL); - if (time2str(tv, timestr, sizeof(timestr)) < 0){ + if (time2str(&tv, timestr, sizeof(timestr)) < 0){ clicon_err(OE_UNIX, errno, "time2str"); goto done; } diff --git a/util/clixon_util_stream.c b/util/clixon_util_stream.c index 69f2f0c52..4a26b395d 100644 --- a/util/clixon_util_stream.c +++ b/util/clixon_util_stream.c @@ -241,10 +241,9 @@ main(int argc, char **argv) break; case 's': /* start-time */ if (*optarg == '+' || *optarg == '-'){ - struct timeval t; - t = now; + struct timeval t = now; t.tv_sec += atoi(optarg); - if (time2str(t, start, sizeof(start)) < 0) + if (time2str(&t, start, sizeof(start)) < 0) goto done; } else @@ -252,10 +251,9 @@ main(int argc, char **argv) break; case 'e': /* stop-time */ if (*optarg == '+' || *optarg == '-'){ - struct timeval t; - t = now; + struct timeval t = now; t.tv_sec += atoi(optarg); - if (time2str(t, stop, sizeof(stop)) < 0) + if (time2str(&t, stop, sizeof(stop)) < 0) goto done; } else