[LTP] [PATCH] matrix_mult: Fix matrices'array out of bounds

Hao Ge gehao@kylinos.cn
Mon Apr 3 08:23:21 CEST 2023


When i=0,i_m=MATRIX_SIZE-i,calculation results
is MATRIX_SIZE(100),it will cause out of bounds
due to this array max item is MATRIX_SIZE -1;

So we should have a minus 1 operation for i_m.

Signed-off-by: Hao Ge <gehao@kylinos.cn>
---
 testcases/realtime/func/matrix_mult/matrix_mult.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/realtime/func/matrix_mult/matrix_mult.c b/testcases/realtime/func/matrix_mult/matrix_mult.c
index e2a55628a..c32092344 100644
--- a/testcases/realtime/func/matrix_mult/matrix_mult.c
+++ b/testcases/realtime/func/matrix_mult/matrix_mult.c
@@ -100,7 +100,7 @@ static void matrix_mult(struct matrices *matrices)
 
 	matrix_init(matrices->A, matrices->B);
 	for (i = 0; i < MATRIX_SIZE; i++) {
-		int i_m = MATRIX_SIZE - i;
+		int i_m = MATRIX_SIZE - i - 1;
 		for (j = 0; j < MATRIX_SIZE; j++) {
 			double sum = matrices->A[i_m][j] *  matrices->B[j][i];
 			for (k = 0; k < MATRIX_SIZE; k++)
-- 
2.25.1


No virus found
		Checked by Hillstone Network AntiVirus


More information about the ltp mailing list