From 093e1b2db1862187fce73bb2db2fe066b095e277 Mon Sep 17 00:00:00 2001 From: Nimish Date: Mon, 12 Aug 2024 09:59:12 +0530 Subject: [PATCH] Update tensor1d.c for index check in get_tensor --- tensor1d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensor1d.c b/tensor1d.c index 8ee3fe6..2961fb4 100644 --- a/tensor1d.c +++ b/tensor1d.c @@ -119,7 +119,7 @@ float tensor_getitem(Tensor* t, int ix) { // handle negative indices by wrapping around if (ix < 0) { ix = t->size + ix; } // oob indices raise IndexError (and we return NaN) - if (ix >= t->size) { + if (ix < 0 || ix >= t->size) { fprintf(stderr, "IndexError: index %d is out of bounds of %d\n", ix, t->size); return NAN; }