From 5503c140dac2f22eee2a620703aff57f28b4512b Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Sat, 7 Sep 2019 13:04:14 -0600 Subject: Fix invalid wait values Previously, bad wait values default to 0 (like `sdf`) because atoi returns 0 when it doesn't understand the input. This caused very rapid color changing. Now we check if wait is set to less than 1, assuming an error, and defaults to 1000. This accounts for when users pass negative values and strings. Also removed unused `highest` variable. --- src/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 79a7933..700b966 100644 --- a/src/main.c +++ b/src/main.c @@ -107,7 +107,6 @@ void channel_fade(int* a, int* b) { */ void rgb_fade(int r, int g, int b, int wait) { int i = 0; - int highest = 0; int colors[3] = {r, g, b}; int size = 3; @@ -133,6 +132,11 @@ int main(int argc, char* argv[]) { if(argc == 2) wait = atoi(argv[1]); + if(wait < 1) { + printf("Error setting wait. Defaulting to 1000\n"); + wait=1000; + } + load_current_state(&r, &g, &b); rgb_fade(r, g, b, wait); } -- cgit v1.2.3