From: Ivan Maidanski Date: Fri, 21 Oct 2016 18:57:15 +0000 (+0300) Subject: Workaround 'tainted int used as loop bound' static analysis tool warning X-Git-Tag: v7.6.2~375 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6351d2ec35282e24129b2eee2f4a6c02d816b532;p=gc Workaround 'tainted int used as loop bound' static analysis tool warning (Cherry-pick commits 1868a90 and 0f23ec4 from 'master' branch.) No need to check upper bound of n here, so a dummy check is added. * tests/test_cpp.cc (main) [LINT2]: Check upper bound of n signed local variable (the check is actually dummy). * tests/test_cpp.cc (main): Reformat code (which handles n variable). --- diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index ed98fb73..0edc20ef 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -237,9 +237,16 @@ void* Undisguise( GC_word i ) { *xptr = x; x = 0; # endif - if (argc != 2 || (0 >= (n = atoi( argv[ 1 ] )))) { - GC_printf( "usage: test_cpp number-of-iterations\nAssuming 10 iters\n" ); - n = 10;} + if (argc != 2 + || (n = atoi(argv[1])) <= 0 +# ifdef LINT2 + || n >= (int)(~0U >> 1) - 1 +# endif + ) { + GC_printf("usage: test_cpp number-of-iterations\n" + "Assuming 10 iters\n"); + n = 10; + } for (iters = 1; iters <= n; iters++) { GC_printf( "Starting iteration %d\n", iters );