src/common.c: parse_values: Add error handling.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 31 Oct 2010 14:44:18 +0000 (15:44 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 31 Oct 2010 14:44:18 +0000 (15:44 +0100)
src/common.c

index 1cef5e1..87d7bf0 100644 (file)
@@ -981,8 +981,20 @@ int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds)
                        if (strcmp ("N", ptr) == 0)
                                vl->time = cdtime ();
                        else
-                               /* FIXME: Add error checking here. */
-                               vl->time = DOUBLE_TO_CDTIME_T (atof (ptr));
+                       {
+                               char *endptr = NULL;
+                               double tmp;
+
+                               errno = 0;
+                               tmp = strtod (ptr, &endptr);
+                               if ((errno != 0)                    /* Overflow */
+                                               || (endptr == ptr)  /* Invalid string */
+                                               || (endptr == NULL) /* This should not happen */
+                                               || (*endptr != 0))  /* Trailing chars */
+                                       return (-1);
+
+                               vl->time = DOUBLE_TO_CDTIME_T (tmp);
+                       }
                }
                else
                {