1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 07:16:37 +02:00

irc: do not use strptime to parse a time as float number (issue #1289)

This commit is contained in:
Sébastien Helleu
2019-01-13 15:25:22 +01:00
parent 1b26d0608f
commit 4fab6dcd05
+16 -6
View File
@@ -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);
}
}