On 08.10.21 11:14, Michael Adler wrote:
> The previous comparison with LONG_{MIN,MAX} was (almost) always false
> because the variable for the comparison had already been casted from
> long to int.
> 
> Signed-off-by: Michael Adler <[email protected]>
> ---
>  tools/bg_setenv.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
> index d26eeed..08beecc 100644
> --- a/tools/bg_setenv.c
> +++ b/tools/bg_setenv.c
> @@ -221,16 +221,19 @@ static error_t set_uservars(char *arg)
>  static int parse_int(char *arg)
>  {
>       char *tmp;
> -     int i;
> +     long i;
>  
>       errno = 0;
>       i = strtol(arg, &tmp, 10);
> -     if ((errno == ERANGE && (i == LONG_MAX || i == LONG_MIN)) ||
> -         (errno != 0 && i == 0) || (tmp == arg)) {
> +     if (errno == ERANGE /* out of range */
> +             || (errno != 0 && i == 0) /* no conversion was performed */
> +             || (tmp == arg || *tmp != '\0') /* invalid input */
> +             || (i < INT_MIN || i > INT_MAX) /* not a valid int */
> +             ) {
>               errno = EINVAL;
>               return -1;
>       }
> -     return i;
> +     return (int) i;
>  }
>  
>  static error_t parse_opt(int key, char *arg, struct argp_state *state)
> 

Thanks, applied. I've only reformatted things a bit, please see next.

Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/dd3d4ccd-03b7-5f58-de48-570ee96976c4%40siemens.com.

Reply via email to