From 669b9d3ddf4bf529c16f1ed8d010e653d349e9ba Mon Sep 17 00:00:00 2001 From: Nikolaos Kavvadias Date: Fri, 16 Apr 2021 12:45:10 +0200 Subject: [PATCH 1/4] rtest_ac_normalize.cpp: Avoid UB in accessing the variable --- tests/rtest_ac_normalize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rtest_ac_normalize.cpp b/tests/rtest_ac_normalize.cpp index 3e3e341..f9753e9 100644 --- a/tests/rtest_ac_normalize.cpp +++ b/tests/rtest_ac_normalize.cpp @@ -110,7 +110,7 @@ int test_driver_fixed( } bool incorrect = false; - int nocalls, expret_fixed, expret_complex; + int nocalls=0, expret_fixed, expret_complex; // test fixed-point real and complex. From 0712eef38933233987e8559a84abdbde5990ac3a Mon Sep 17 00:00:00 2001 From: Nikolaos Kavvadias Date: Fri, 16 Apr 2021 12:45:38 +0200 Subject: [PATCH 2/4] rtest_ac_normalize.cpp: Fix calculation of accepted range for fixed avoid ``` [rtest_ac_normalize.cpp:129]: (warning) Logical conjunction always evaluates to false: output_fixed >= 1 && output_fixed < -1. ``` --- tests/rtest_ac_normalize.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/rtest_ac_normalize.cpp b/tests/rtest_ac_normalize.cpp index f9753e9..3af5e86 100644 --- a/tests/rtest_ac_normalize.cpp +++ b/tests/rtest_ac_normalize.cpp @@ -126,7 +126,9 @@ int test_driver_fixed( // This flag is set to false if the real output is incorrect bool incorrect_fixed = (output_fixed.to_double() * pow(2, (double)expret_fixed) != input_fixed); // Make sure that the range of the normalized output is as expected. - incorrect_fixed = incorrect_fixed || ((output_fixed > -0.5) && (output_fixed < 0.5)) || ((output_fixed >= 1) && (output_fixed < -1)); + // Expected range is: [-1.0, -0.5] U [0.5, 1.0] + bool in_range = ((output_fixed >= -1) && (output_fixed <= -0.5)) || ((output_fixed >= 0.5) && (output_fixed <= 1)); + incorrect_fixed = incorrect_fixed || !in_range; // Inputs and outputs being zero is a special case, and the range-checking above will produce a false negative in such a case. This is taken care of below. if (output_fixed == 0 && input_fixed == 0) {incorrect_fixed = false;} From 02bb98e760d46602d6c21eee6466a24bcd01efa6 Mon Sep 17 00:00:00 2001 From: Nikolaos Kavvadias Date: Fri, 16 Apr 2021 12:46:16 +0200 Subject: [PATCH 3/4] rtest_ac_normalize.cpp: Fix calculating effective range for complex avoid ``` [rtest_ac_normalize.cpp:137]: (warning) Logical conjunction always evaluates to false: EXPR >= 1 && EXPR < -1. ``` --- tests/rtest_ac_normalize.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/rtest_ac_normalize.cpp b/tests/rtest_ac_normalize.cpp index 3af5e86..3d1890d 100644 --- a/tests/rtest_ac_normalize.cpp +++ b/tests/rtest_ac_normalize.cpp @@ -136,7 +136,9 @@ int test_driver_fixed( bool incorrect_complex = ((cmplx_output_fixed.r().to_double()*pow(2, (double)expret_complex) != cmplx_input_fixed.r().to_double()) || (cmplx_output_fixed.i().to_double()*pow(2, (double)expret_complex) != cmplx_input_fixed.i().to_double())); // Make sure that the range of the normalized output is as expected. incorrect_complex = incorrect_complex || ((cmplx_output_fixed.r() > -0.5) && (cmplx_output_fixed.r() < 0.5) && (cmplx_output_fixed.i() > -0.5) && (cmplx_output_fixed.i() < 0.5)); - incorrect_complex = incorrect_complex || (cmplx_output_fixed.r() >= 1) || (cmplx_output_fixed.r() < -1) || (cmplx_output_fixed.i() >= 1) && (cmplx_output_fixed.i() < -1); + // Expected range is: [-1.0, +1.0] + in_range = ((cmplx_output_fixed.r() >= -1) && (cmplx_output_fixed.r() <= 1)) || ((cmplx_output_fixed.i() >= -1) && (cmplx_output_fixed.i() <= 1)); + incorrect_complex = incorrect_complex || !in_range; // Inputs and outputs being zero is a special case, and the range-checking above will produce a false negative in such a case. This is taken care of below. if (cmplx_output_fixed.r() == 0 && cmplx_output_fixed.i() == 0 && cmplx_input_fixed.r() == 0 && cmplx_input_fixed.i() == 0) {incorrect_complex = false;} From f8294a1e5abb5cb39443579bc18d96ddfeea7d6f Mon Sep 17 00:00:00 2001 From: Nikolaos Kavvadias Date: Tue, 20 Apr 2021 19:07:38 +0200 Subject: [PATCH 4/4] rtest_ac_normalize.cpp: Remove unused variable --- tests/rtest_ac_normalize.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/rtest_ac_normalize.cpp b/tests/rtest_ac_normalize.cpp index 3d1890d..67052c1 100644 --- a/tests/rtest_ac_normalize.cpp +++ b/tests/rtest_ac_normalize.cpp @@ -110,7 +110,7 @@ int test_driver_fixed( } bool incorrect = false; - int nocalls=0, expret_fixed, expret_complex; + int expret_fixed, expret_complex; // test fixed-point real and complex. @@ -121,7 +121,6 @@ int test_driver_fixed( cmplx_input_fixed.r() = i; cmplx_input_fixed.i() = j; test_ac_normalize(input_fixed, output_fixed, cmplx_input_fixed, cmplx_output_fixed, expret_fixed, expret_complex); - nocalls++; // This flag is set to false if the real output is incorrect bool incorrect_fixed = (output_fixed.to_double() * pow(2, (double)expret_fixed) != input_fixed);