[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH 2/2] libbb/u_signal_names.c: don't check errno after bb_strtou
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2018-10-31 10:30:27
Message-ID: CAK1hOcNx_Viezf+NXxOOTeh0JPk_aJfv1cThH9poRZczaK6aEg () mail ! gmail ! com
[Download RAW message or body]
Applied, thanks!
On Wed, Sep 12, 2018 at 5:39 PM Rasmus Villemoes
<rasmus.villemoes@prevas.dk> wrote:
>
> 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. Seems to save ~34 or
> ~45 bytes (depending on RTMINMAX_USE_LIBC_DEFINITIONS).
>
> 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.
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
> libbb/u_signal_names.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c
> index 5ef5c3f28..88f63192d 100644
> --- a/libbb/u_signal_names.c
> +++ b/libbb/u_signal_names.c
> @@ -151,8 +151,12 @@ int FAST_FUNC get_signum(const char *name)
> unsigned i;
> unsigned sigrtmin, sigrtmax;
>
> + /* bb_strtou returns UINT_MAX on error. We should be able to
> + * assume NSIG is not that big... Hence no need to check errno
> + * after bb_strtou(). */
> + BUILD_BUG_ON(NSIG >= UINT_MAX);
> 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;
> @@ -200,7 +204,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;
> }
> }
> @@ -209,7 +213,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;
> }
> }
> --
> 2.16.4
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic