From 85f94874c912e0cc09a69404929b6d7b4f4fc1c6 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Fri, 14 Dec 2018 12:24:24 -0600 Subject: fix another bug in combinations_with_replacement() Also, fix a few memory leaks in test.c. --- src/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/misc.c') diff --git a/src/misc.c b/src/misc.c index 56760e4..a610944 100644 --- a/src/misc.c +++ b/src/misc.c @@ -726,14 +726,14 @@ void combinations_with_replacement(size_t n, size_t r, size_t *result, size_t *l size_t i, j; size_t *tmp; - tmp = malloc(sizeof(size_t)*n*ipow(n,r)); + tmp = malloc(sizeof(size_t)*r*ipow(n,r)); product(n,r,tmp); *len = 0; for (i = 0; i < ipow(n,r); i++) { if (is_sorted(tmp+i*r,r)) { - for (j = 0; j < n; j++) { + for (j = 0; j < r; j++) { result[(*len)*r+j] = tmp[i*r+j]; } *len += 1; -- cgit