From 9da8544408192a51a2f07e303809dcebfef3099f Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Thu, 25 Apr 2024 11:27:26 -0400 Subject: [PATCH] TIME: malloc and HHmmss Nits; Remove Unneeded time/date strings from Ncurses; --- src/dsd_ncurses.c | 10 +++------- src/dsd_time.c | 12 ++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index 193eb1b..8002065 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -32,8 +32,6 @@ static char alias_ch[10][50]; int reset = 0; char * timestr; char * datestr; -char * timestrC; -char * datestrH; int tg; int tgR; int tgn; @@ -1955,9 +1953,9 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) timestr = getTime(); datestr = getDate(); - //for display - timestrC = getTimeC(); - datestrH = getDateH(); + //NOTE: Any times associates with call history are stored + //in the array and need to be set by passing those values into + //getTimeN and getDateN if (opts->audio_in_type != 1) //can't run getch/menu when using STDIN - { @@ -4846,8 +4844,6 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) //allocated memory pointer needs to be free'd if (timestr != NULL) free (timestr); if (datestr != NULL) free (datestr); - if (timestrC != NULL) free (timestrC); - if (datestrH != NULL) free (datestrH); } //end ncursesPrinter diff --git a/src/dsd_time.c b/src/dsd_time.c index e04dabb..d67e305 100644 --- a/src/dsd_time.c +++ b/src/dsd_time.c @@ -6,22 +6,22 @@ * 2024-04 DSD-FME Florida Man Edition *-----------------------------------------------------------------------------*/ -//TODO: Make sure everything still works as intended, no random crashes on free (timestr) +//TODO: Make sure everything still works as intended, every free(timestr) has a NULL check first, //make sure no other loose or random time functions embedded in other files or functions, etc #include "dsd.h" -//get hhmmss timestamp no colon (file operations) +//get HHmmss timestamp no colon (file operations) char * getTime() { - char * curr = (char *) malloc(9); + char * curr = (char *) malloc(7); time_t t = time(NULL); struct tm * ptm = localtime(& t); sprintf(curr,"%02d%02d%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec); return curr; } -//get hh:mm:ss timestamp with colon (Ncurses Display) +//get HH:mm:ss timestamp with colon (Sync/Console Display) char * getTimeC() { char * curr = (char *) malloc(9); @@ -31,7 +31,7 @@ char * getTimeC() return curr; } -//get hh:mm:ss timestamp with colon (Ncurses Display) +//get HH:mm:ss timestamp with colon (Ncurses Call History) char * getTimeN(time_t t) { char * curr = (char *) malloc(9); @@ -50,7 +50,7 @@ char * getDate() return curr; } -//get YYYY-MM-DD with hyphen (Ncurses Display) +//get YYYY-MM-DD with hyphen (Sync/Console Display) char * getDateH() { char * curr = (char *) malloc(27);