summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2019-06-09 13:23:06 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2019-06-09 13:23:06 -0700
commit5172321febbd76a55f32c859996d8923333da3a1 (patch)
tree20ca210078a7cc65d97bc6d16a4be2f84dcd5100
parent92de87f30c2fd25245e3e345633fe497665b5448 (diff)
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 <alan.coopersmith@oracle.com>
-rw-r--r--xbacklight.c8
1 files 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;
}