diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-01-13 15:25:22 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-01-13 15:25:22 +0100 |
commit | 4fab6dcd05de0e2a60c1d370ed37ad30a61c10cf (patch) | |
tree | 8fceceac052351c145e87b63dd300e5bf7745bf2 /src | |
parent | 1b26d0608fbddba7fbb93fbeee7a845650b00f23 (diff) | |
download | weechat-4fab6dcd05de0e2a60c1d370ed37ad30a61c10cf.zip |
irc: do not use strptime to parse a time as float number (issue #1289)
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 492238198..9403d6d5a 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -6090,18 +6090,19 @@ irc_protocol_parse_time (const char *time) { time_t time_value, time_msg, time_gm, time_local; struct tm tm_date, tm_date_gm, tm_date_local; + long value; + char *time2, *pos, *error; if (!time || !time[0]) return 0; time_value = 0; - /* initialize structure, because strptime does not do it */ - memset (&tm_date, 0, sizeof (struct tm)); - if (strchr (time, '-')) { /* date is with ISO 8601 format: "2012-11-24T07:41:02.018Z" */ + /* initialize structure, because strptime does not do it */ + memset (&tm_date, 0, sizeof (struct tm)); if (strptime (time, "%Y-%m-%dT%H:%M:%S", &tm_date)) { if (tm_date.tm_year > 0) @@ -6118,10 +6119,19 @@ irc_protocol_parse_time (const char *time) else { /* date is with timestamp format: "1353403519.478" */ - if (strptime (time, "%s", &tm_date)) + time2 = strdup (time); + if (time2) { - if (tm_date.tm_year > 0) - time_value = mktime (&tm_date); + pos = strchr (time2, '.'); + if (pos) + pos[0] = '\0'; + pos = strchr (time2, ','); + if (pos) + pos[0] = '\0'; + value = strtol (time2, &error, 10); + if (error && !error[0] && (value >= 0)) + time_value = (int)value; + free (time2); } } |