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 <ant.v.morya...@gmail.com> --- 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': -- 2.30.2 _______________________________________________ busybox mailing list busybox@busybox.net https://lists.busybox.net/mailman/listinfo/busybox