aboutsummaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2018-12-14 12:24:24 -0600
committertlatorre <tlatorre@uchicago.edu>2018-12-14 12:24:24 -0600
commit85f94874c912e0cc09a69404929b6d7b4f4fc1c6 (patch)
tree3ba673f263e990eca664a317fea72edeeeb559e3 /src/misc.c
parent99db8e8e14696bfbf812b655d4a9160500afea11 (diff)
downloadsddm-85f94874c912e0cc09a69404929b6d7b4f4fc1c6.tar.gz
sddm-85f94874c912e0cc09a69404929b6d7b4f4fc1c6.tar.bz2
sddm-85f94874c912e0cc09a69404929b6d7b4f4fc1c6.zip
fix another bug in combinations_with_replacement()
Also, fix a few memory leaks in test.c.
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c4
1 files changed, 2 insertions, 2 deletions
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;