Merge pull request #644 from manuelluis/mlsr/putnotif-fix_time
authorPierre-Yves Ritschard <pyr@spootnik.org>
Sat, 26 Jul 2014 07:36:56 +0000 (09:36 +0200)
committerPierre-Yves Ritschard <pyr@spootnik.org>
Sat, 26 Jul 2014 07:36:56 +0000 (09:36 +0200)
Fix the conversion of time option in PUTNOTIF from timestamp to cdtime_t

src/utils_cmd_putnotif.c

index 5a9faff..d3cf383 100644 (file)
@@ -49,13 +49,18 @@ static int set_option_severity (notification_t *n, const char *value)
 
 static int set_option_time (notification_t *n, const char *value)
 {
-  time_t tmp;
-  
-  tmp = (time_t) atoi (value);
-  if (tmp <= 0)
+  char *endptr = NULL;
+  double tmp;
+
+  errno = 0;
+  tmp = strtod (value, &endptr);
+  if ((errno != 0)         /* Overflow */
+      || (endptr == value) /* Invalid string */
+      || (endptr == NULL)  /* This should not happen */
+      || (*endptr != 0))   /* Trailing chars */
     return (-1);
 
-  n->time = tmp;
+  n->time = DOUBLE_TO_CDTIME_T (tmp);
 
   return (0);
 } /* int set_option_time */