From 5172321febbd76a55f32c859996d8923333da3a1 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 9 Jun 2019 13:23:06 -0700 Subject: atof_or_die: Also die if nothing was converted Needed on Solaris to catch errors with strings that have no numbers Signed-off-by: Alan Coopersmith --- xbacklight.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xbacklight.c b/xbacklight.c index b7c8011..64a043d 100644 --- a/xbacklight.c +++ b/xbacklight.c @@ -64,9 +64,13 @@ static double atof_or_die (char *str) { double retval; + char *endptr = NULL; errno = 0; - retval = strtod(str, NULL); - if (errno) usage(1); + retval = strtod(str, &endptr); + if ((errno != 0) || (endptr == str)) { + fprintf(stderr, "%s: invalid argument '%s'\n", program_name, str); + usage(1); + } return retval; } -- cgit v1.2.3