Code

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 1cef5e1756258b75dc6fc4cd89f28522daa9851d..87d7bf0833e18fafde04d34555a86cbfd6c4afab 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
                {