Commit 4fab6dcd authored by Sébastien Helleu's avatar Sébastien Helleu

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

parent 1b26d060
......@@ -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);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment