Improve error checking of c_strtod call.
authorBruno Haible <bruno@clisp.org>
Wed, 21 Jan 2009 22:55:58 +0000 (23:55 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 21 Jan 2009 22:55:58 +0000 (23:55 +0100)
ChangeLog
lib/getloadavg.c

index 5dd2451dad95adb4d921849b2ebaf699dc71288c..a6e5634d3cbc31e07931300dbbfdde2b1e78da5f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-21  Bruno Haible  <bruno@clisp.org>
+
+       * lib/getloadavg.c (getloadavg): Check c_strtod result against error
+       conditions other than overflow.
+
 2009-01-21  Bruno Haible  <bruno@clisp.org>
 
        * lib/c-strtod.c: Include errno.h.
index 5c32f9f9ca4967a75888e8af8b87725518f7013b..5a4005cee0b9e5d6af9ef8165582a1f440598956 100644 (file)
@@ -1,8 +1,8 @@
 /* Get the system load averages.
 
    Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994,
-   1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008 Free Software
-   Foundation, Inc.
+   1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free
+   Software Foundation, Inc.
 
    NOTE: The canonical source of this file is maintained with gnulib.
    Bugs can be reported to bug-gnulib@gnu.org.
@@ -621,8 +621,11 @@ getloadavg (double loadavg[], int nelem)
   for (elem = 0; elem < nelem; elem++)
     {
       char *endptr;
-      double d = c_strtod (ptr, &endptr);
-      if (ptr == endptr)
+      double d;
+
+      errno = 0;
+      d = c_strtod (ptr, &endptr);
+      if (ptr == endptr || (d == 0 && errno != 0))
        {
          if (elem == 0)
            return -1;