Check errors for overflow, underflow, incomplete string conversion.

Signed-off-by: Yann Droneaud <[email protected]>

---
 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

_______________________________________________
xorg-devel mailing list
[email protected]
http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to