libbb/u_signal_names.c: don't check errno after bb_strtou
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>
Wed, 12 Sep 2018 14:06:37 +0000 (16:06 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 31 Oct 2018 10:28:37 +0000 (11:28 +0100)
Since we're comparing the return value to a smallish integer anyway, we
might as well use that bb_strtou() returns UINT_MAX for malformed
input. Referencing errno is kinda bloaty on glibc.

While NSIG is not in POSIX, we do already rely on it being defined,
compile-time const and smallish, since arrays in struct globals_misc are
defined in terms of it.

function                                             old     new   delta
get_signum                                           312     286     -26

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/u_signal_names.c

index 866ca85fda9e19ad1bdd2a3a7e3e80e994373f5c..f7d598c7ad1482986d7e898f1e238e5c4d54fa99 100644 (file)
@@ -153,8 +153,12 @@ int FAST_FUNC get_signum(const char *name)
 {
        unsigned i;
 
+       /* bb_strtou returns UINT_MAX on error. NSIG is smaller
+        * than UINT_MAX on any sane Unix. Hence no need
+        * to check errno after bb_strtou().
+        */
        i = bb_strtou(name, NULL, 10);
-       if (!errno && i < NSIG) /* for shells, we allow 0 too */
+       if (i < NSIG) /* for shells, we allow 0 too */
                return i;
        if (strncasecmp(name, "SIG", 3) == 0)
                name += 3;
@@ -204,7 +208,7 @@ int FAST_FUNC get_signum(const char *name)
                                return sigrtmin;
                        if (name[5] == '+') {
                                i = bb_strtou(name + 6, NULL, 10);
-                               if (!errno && i <= sigrtmax - sigrtmin)
+                               if (i <= sigrtmax - sigrtmin)
                                        return sigrtmin + i;
                        }
                }
@@ -213,7 +217,7 @@ int FAST_FUNC get_signum(const char *name)
                                return sigrtmax;
                        if (name[5] == '-') {
                                i = bb_strtou(name + 6, NULL, 10);
-                               if (!errno && i <= sigrtmax - sigrtmin)
+                               if (i <= sigrtmax - sigrtmin)
                                        return sigrtmax - i;
                        }
                }