]> granicus.if.org Git - procps-ng/commitdiff
free: Parse -s option correctly.
authorCraig Small <csmall@enc.com.au>
Sat, 8 Aug 2015 11:04:01 +0000 (21:04 +1000)
committerCraig Small <csmall@enc.com.au>
Sat, 8 Aug 2015 11:04:01 +0000 (21:04 +1000)
If the -s option was the first option on the command line, free
would report seconds argument failed. This only appeared on the
Debian free, not the one in git.

Closer examination revealed that if a valid float string is
given to strtof() it doesn't set errno to 0, but just leaves it
alone. As we are explicitly testing errno for overflows, this
means the previous errno change is picked up here.

The simple answer is to set errno to 0 before calling strtof().

References:
 https://bugs.debian/org/733758
 https://enc.com.au/2015/08/08/be-careful-with-errno/

NEWS
free.c

diff --git a/NEWS b/NEWS
index a02834804450afb57481c2916ea44b3f7e3b8a64..af9850141d802b781aa2e5c6bc7e5e056ab4677d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ procps-ng-NEXT
   * top once again will fully honor a saved rcfile,
     without requiring --disable-modern-top. Debian #762928, #762947
   * vmstat: Not crash if partition appears before disk Debian #736628
+  * free: -s without -c works Debian #733758
 
 procps-ng-3.3.10
 ----------------
diff --git a/free.c b/free.c
index b19e07ff8112d9d7c591ce8305c79f69c7a4da6a..6c72138c70a18f85de9b6d48d4dccbc7b80fe99a 100644 (file)
--- a/free.c
+++ b/free.c
@@ -323,6 +323,7 @@ int main(int argc, char **argv)
                        break;
                case 's':
                        flags |= FREE_REPEAT;
+                       errno = 0;
                        args.repeat_interval = (1000000 * strtof(optarg, &endptr));
                        if (errno || optarg == endptr || (endptr && *endptr))
                                xerrx(EXIT_FAILURE, _("seconds argument `%s' failed"), optarg);