[PATCH] utils: Remove always true checks

Kang-Che Sung explorer09 at gmail.com
Thu Aug 22 17:48:08 UTC 2024


Maks Mishin <maks.mishinfz at gmail.com> 於 2024年8月23日 星期五寫道:
> Expression 'res <= 4294967295UL' is always true , which may be caused
> by a logical error: 'res' has a type 'unsigned long' with minimum value
'0'
> and a maximum value '4294967295'
>
> Found by the static analyzer Svace.
>
> Signed-off-by: Maks Mishin <maks.mishinFZ at gmail.com>
> ---
>  networking/libiproute/utils.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c
> index 3cce4a06e..9e8600f34 100644
> --- a/networking/libiproute/utils.c
> +++ b/networking/libiproute/utils.c
> @@ -42,7 +42,7 @@ unsigned FAST_FUNC get_unsigned(char *arg, const char
*errmsg)
>         if (*arg) {
>                 res = strtoul(arg, &ptr, 0);
>  //FIXME: "" will be accepted too, is it correct?!
> -               if (!*ptr && res <= UINT_MAX) {
> +               if (!*ptr) {
>                         return res;
>                 }
>         }
> @@ -57,7 +57,7 @@ uint32_t FAST_FUNC get_u32(char *arg, const char
*errmsg)
>         if (*arg) {
>                 res = strtoul(arg, &ptr, 0);
>  //FIXME: "" will be accepted too, is it correct?!
> -               if (!*ptr && res <= 0xFFFFFFFFUL) {
> +               if (!*ptr) {
>                         return res;
>                 }
>         }
> --

No, I don't think removal is the right way. `long` is 64-bit in 64-bit OS
(the "LP64" data model). You get the always true condition only on 32-bit
systems, or on Windows, which uses LLP64.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20240823/1ee2f7db/attachment-0001.html>


More information about the busybox mailing list