From ac39da6c97303fde8267b0fc31f183b34257594e Mon Sep 17 00:00:00 2001 From: fossedihelm Date: Wed, 6 Dec 2017 15:22:28 +0100 Subject: [PATCH] check if argument of initial-value is in the [0,100 range --- src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e59fac8a..6bc7d5df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -137,12 +137,21 @@ fn setup(args: &[String]) -> Setup { let initial_volume; if matches.opt_present("initial-volume"){ if matches.opt_str("initial-volume").unwrap().parse::().is_ok(){ - initial_volume = matches.opt_str("initial-volume").unwrap().parse::().unwrap()* 0xFFFF as i32 / 100 ; + if matches.opt_str("initial-volume").unwrap().parse::().unwrap() < 0 { + initial_volume = 0 as i32; } + else if matches.opt_str("initial-volume").unwrap().parse::().unwrap() > 100{ + initial_volume = 0xFFFF as i32; + } + else{ + initial_volume = matches.opt_str("initial-volume").unwrap().parse::().unwrap()* 0xFFFF as i32 / 100 ; + } + + } else { initial_volume = 0x8000 as i32; - } } + } else{ initial_volume = 0x8000 as i32; }