Skip to content
Snippets Groups Projects
Commit 5aafe28c authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Re-work the string constant usage of utimestr()

To make Coverity and my adult-self happy.
parent f3c99077
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -2530,73 +2530,76 @@ void bottomline(int mode) ...@@ -2530,73 +2530,76 @@ void bottomline(int mode)
char *utimestr(time_t *intime) char *utimestr(time_t *intime)
{ {
static char str[25]; static char str[25];
char wday[4],mon[4],mer[3],hour; const char* wday="";
const char* mon="";
const char* mer= "";
int hour;
struct tm *gm; struct tm *gm;
gm=localtime(intime); gm=localtime(intime);
switch(gm->tm_wday) { switch(gm->tm_wday) {
case 0: case 0:
strcpy(wday,"Sun"); wday = "Sun";
break; break;
case 1: case 1:
strcpy(wday,"Mon"); wday = "Mon";
break; break;
case 2: case 2:
strcpy(wday,"Tue"); wday = "Tue";
break; break;
case 3: case 3:
strcpy(wday,"Wed"); wday = "Wed";
break; break;
case 4: case 4:
strcpy(wday,"Thu"); wday = "Thu";
break; break;
case 5: case 5:
strcpy(wday,"Fri"); wday = "Fri";
break; break;
case 6: case 6:
strcpy(wday,"Sat"); wday = "Sat";
break; break;
} }
switch(gm->tm_mon) { switch(gm->tm_mon) {
case 0: case 0:
strcpy(mon,"Jan"); mon = "Jan";
break; break;
case 1: case 1:
strcpy(mon,"Feb"); mon = "Feb";
break; break;
case 2: case 2:
strcpy(mon,"Mar"); mon = "Mar";
break; break;
case 3: case 3:
strcpy(mon,"Apr"); mon = "Apr";
break; break;
case 4: case 4:
strcpy(mon,"May"); mon = "May";
break; break;
case 5: case 5:
strcpy(mon,"Jun"); mon = "Jun";
break; break;
case 6: case 6:
strcpy(mon,"Jul"); mon = "Jul";
break; break;
case 7: case 7:
strcpy(mon,"Aug"); mon = "Aug";
break; break;
case 8: case 8:
strcpy(mon,"Sep"); mon = "Sep";
break; break;
case 9: case 9:
strcpy(mon,"Oct"); mon = "Oct";
break; break;
case 10: case 10:
strcpy(mon,"Nov"); mon = "Nov";
break; break;
case 11: case 11:
strcpy(mon,"Dec"); mon = "Dec";
break; break;
} }
if(gm->tm_hour>=12) { if(gm->tm_hour>=12) {
strcpy(mer,"pm"); mer = "pm";
hour=gm->tm_hour; hour=gm->tm_hour;
if (hour > 12) if (hour > 12)
hour-=12; hour-=12;
...@@ -2606,9 +2609,9 @@ char *utimestr(time_t *intime) ...@@ -2606,9 +2609,9 @@ char *utimestr(time_t *intime)
hour=12; hour=12;
else else
hour=gm->tm_hour; hour=gm->tm_hour;
strcpy(mer,"am"); mer = "am";
} }
sprintf(str,"%s %s %02d %4d %02d:%02d %s",wday,mon,gm->tm_mday,1900+gm->tm_year safe_snprintf(str, sizeof(str), "%s %s %02d %4d %02d:%02d %s",wday,mon,gm->tm_mday,1900+gm->tm_year
,hour,gm->tm_min,mer); ,hour,gm->tm_min,mer);
return(str); return(str);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment