public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] matrix_mult: Fix matrices'array out of bounds
@ 2023-04-03  6:23 Hao Ge
  2023-04-03 15:15 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Hao Ge @ 2023-04-03  6:23 UTC (permalink / raw)
  To: ltp; +Cc: gehao

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-03 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-03  6:23 [LTP] [PATCH] matrix_mult: Fix matrices'array out of bounds Hao Ge
2023-04-03 15:15 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox