On Wed,  5 Feb 2025 18:38:05 +0300
Anton Moryakov <[email protected]> wrote:

> Report of the static analyzer:
> DIVISION_BY_ZERO.EX Variable xatou(...), 
> whose possible value set allows a zero value at xatonum_template.c:118 by 
> calling function 'xatou' at beep.c:90,
> is used as a denominator at beep.c:90.
> 
> Corrections explained:
> - If xatou(optarg) returns 0, freq is set to 440 instead of  
>   terminating the program.  
> - A warning message is printed to inform the user about the change.  
> - Removed redundant second call to xatou(optarg), using freq  
> 
> Triggers found by static analyzer Svace.
> 
> Signed-off-by: Anton Moryakov <[email protected]>
> 
> ---
>  miscutils/beep.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/miscutils/beep.c b/miscutils/beep.c
> index 724a666c8..2ef3bbfe4 100644
> --- a/miscutils/beep.c
> +++ b/miscutils/beep.c
> @@ -87,6 +87,11 @@ int beep_main(int argc, char **argv)
>               switch (c) {
>               case 'f':
>  /* TODO: what "-f 0" should do? */
> +                     unsigned freq = xatou_range(optarg, 0, 20000);
> +                     if (freq == 0){
> +                             bb_error_msg("frequency cannot be zero, setting 
> to default 440 Hz");
> +                             freq = 440;
> +                     }
>                       tickrate_div_freq = (unsigned)CLOCK_TICK_RATE / 
> xatou(optarg);
>                       continue;
>               case 'l':

Hi,
this looks wrong to me, shouldn't it be:

tickrate_div_freq = (unsigned)CLOCK_TICK_RATE / freq);


P.S: i would drop the error message as beep does this silently, only in debug 
mode
        it is printed that 440 hz is used.

Ciao,
Tito
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to