TIME: Set Allocated Pointers to NULL after free()'d;

This commit is contained in:
lwvmobile
2024-04-25 18:22:28 -04:00
parent 7bcd29abec
commit db036f4dfc
10 changed files with 182 additions and 56 deletions

View File

@@ -14,7 +14,7 @@
//get HHmmss timestamp no colon (file operations)
char * getTime()
{
char * curr = (char *) malloc(7);
char * curr = calloc(7, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr,"%02d%02d%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
@@ -24,7 +24,7 @@ char * getTime()
//get HH:mm:ss timestamp with colon (Sync/Console Display)
char * getTimeC()
{
char * curr = (char *) malloc(9);
char * curr = calloc(9, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
@@ -34,7 +34,7 @@ char * getTimeC()
//get HH:mm:ss timestamp with colon (Ncurses Call History)
char * getTimeN(time_t t)
{
char * curr = (char *) malloc(9);
char * curr = calloc(9, sizeof(char));
struct tm * ptm = localtime(& t);
sprintf(curr, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
return curr;
@@ -43,7 +43,7 @@ char * getTimeN(time_t t)
//get YYYYMMDD without hyphen (file operations)
char * getDate()
{
char * curr = (char *) malloc(25);
char * curr = calloc(25, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr,"%04d%02d%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
@@ -53,7 +53,7 @@ char * getDate()
//get YYYY-MM-DD with hyphen (Sync/Console Display)
char * getDateH()
{
char * curr = (char *) malloc(27);
char * curr = calloc(27, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr, "%04d-%02d-%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
@@ -63,7 +63,7 @@ char * getDateH()
//get YYYY-MM-DD with hyphen (Ncurses Call History)
char * getDateN(time_t t)
{
char * curr = (char *) malloc(27);
char * curr = calloc(27, sizeof(char));
struct tm * ptm = localtime(& t);
sprintf(curr, "%04d-%02d-%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
return curr;