[PATCH 1/2] xrandr: check_strtod(): be pedantic about conversion errors

Yann Droneaud yann at droneaud.fr
Tue Dec 29 02:33:28 PST 2009


Check errors for overflow, underflow, incomplete string conversion.

Signed-off-by: Yann Droneaud <yann at droneaud.fr>

---
 xrandr.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/xrandr.c b/xrandr.c
index 7b4f71a..9b4f402 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -2013,10 +2013,20 @@ check_strtol(char *s)
 static double
 check_strtod(char *s)
 {
-    char *endptr;
-    double result = strtod(s, &endptr);
-    if (s == endptr)
+    char *endptr = NULL;
+    double result;
+    
+    if (s == NULL || *s == '\0')
 	usage();
+
+    errno = 0;
+    result = strtod(s, &endptr);
+    if (s == endptr || 
+	(endptr != NULL && endptr != '\0') ||
+	(result == 0.0 && errno != 0) ||
+	((result == HUGE_VAL || result == -HUGE_VAL) && errno != 0))
+	usage();
+
     return result;
 }
 
-- 
1.6.2.5



More information about the xorg-devel mailing list