From 3e50a372a959f5bbea0cc52570540130cd645556 Mon Sep 17 00:00:00 2001 From: ame Date: Sun, 15 Oct 2023 23:26:21 -0500 Subject: counting sort fix --- src/table.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/table.c') diff --git a/src/table.c b/src/table.c index 795994d..3c023d8 100644 --- a/src/table.c +++ b/src/table.c @@ -358,8 +358,11 @@ int l_countingsort(lua_State* L) { lua_pop(L,1); } + + //required because max can be too big for the stack :c + int* count = malloc(sizeof *count * (max + 1)); + //int count[max + 1]; - int count[max + 1]; for(size_t i = 0; i <= max; i++) count[i] = 0; for(size_t i = 0; i < len; i++){ @@ -381,7 +384,8 @@ int l_countingsort(lua_State* L) { lua_pushnumber(L,out[i]); lua_settable(L, -3); } - + + free(count); return 1; } -- cgit v1.2.3