commit 8a2cad1: [Minor] Lua_tensor: Fix newindex row assignment

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Aug 25 14:49:10 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-08-25 15:41:46 +0100
URL: https://github.com/rspamd/rspamd/commit/8a2cad181848bc7825001bb1a418aa1982c566ab (HEAD -> master)

[Minor] Lua_tensor: Fix newindex row assignment

---
 src/lua/lua_tensor.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/lua/lua_tensor.c b/src/lua/lua_tensor.c
index 09a10cabc..f8386d6f3 100644
--- a/src/lua/lua_tensor.c
+++ b/src/lua/lua_tensor.c
@@ -383,7 +383,7 @@ lua_tensor_newindex (lua_State *L)
 
 			if (t->ndims == 1) {
 				/* Individual element */
-				if (idx <= t->dim[0]) {
+				if (idx <= t->dim[0] && idx > 0) {
 					rspamd_tensor_num_t value = lua_tonumber (L, 3), old;
 
 					old = t->data[idx - 1];
@@ -405,8 +405,9 @@ lua_tensor_newindex (lua_State *L)
 					if (row) {
 						if (row->ndims == 1) {
 							if (row->dim[0] == t->dim[1]) {
-								if (idx <= t->dim[0]) {
-									memcpy (&t->data[idx * t->dim[0]],
+								if (idx > 0 && idx <= t->dim[0]) {
+									idx --; /* Zero based index */
+									memcpy (&t->data[idx * t->dim[1]],
 											row->data,
 											t->dim[1] * sizeof (rspamd_tensor_num_t));
 


More information about the Commits mailing list