Skip to content

Commit ce63faa

Browse files
committed
Replace sprintf() by strftime() to get the date
1 parent 5151207 commit ce63faa

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/msclogparser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static int parse_date_apache(char * line, logdata *l) {
166166
strptime(datetime, "%A %b %0d %H:%M:%S %Y", &tm);
167167

168168
char date[20] = {0};
169-
sprintf(date, "%04d-%02d-%02d %02d:%02d:%02d", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
169+
strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", &tm);
170170
l->log_date_iso = mscl_stradd(l, date, 19);
171171
float mili = strtof(millisec, NULL);
172172
l->log_date_timestamp = mktime(&tm);
@@ -190,7 +190,7 @@ static int parse_date_nginx(char * line, logdata *l) {
190190
strptime(datetime, "%Y/%m/%d %H:%M:%S", &tm);
191191

192192
char date[20] = {0};
193-
sprintf(date, "%04d-%02d-%02d %02d:%02d:%02d", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
193+
strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", &tm);
194194
l->log_date_iso = mscl_stradd(l, date, 19);
195195
l->log_date_timestamp = mktime(&tm);
196196

0 commit comments

Comments
 (0)