From e2fb0dcb70a97972fa1576a528cb01458f57a85d Mon Sep 17 00:00:00 2001 From: "Martin R. Albrecht" Date: Sun, 19 Jan 2020 17:44:57 -0800 Subject: [PATCH] fix memory violation fixes #72 --- m4ri/mzd.c | 2 +- tests/test_misc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/m4ri/mzd.c b/m4ri/mzd.c index 861905c..922dc3c 100644 --- a/m4ri/mzd.c +++ b/m4ri/mzd.c @@ -1894,7 +1894,7 @@ mzd_t *mzd_submatrix(mzd_t *S, mzd_t const *M, rci_t const startrow, rci_t const } else { wi_t j; for(rci_t i=0; irows[i][j/m4ri_radix] = mzd_read_bits(M, startrow+i, startcol+j, m4ri_radix); S->rows[i][j/m4ri_radix] &= ~S->high_bitmask; S->rows[i][j/m4ri_radix] |= mzd_read_bits(M, startrow+i, startcol+j, ncols - j) & S->high_bitmask; diff --git a/tests/test_misc.c b/tests/test_misc.c index a9a9547..b1a2e32 100644 --- a/tests/test_misc.c +++ b/tests/test_misc.c @@ -76,6 +76,31 @@ int test_png(rci_t m, rci_t n) { return ret; } +int test_submatrix(const rci_t m, const rci_t n, const rci_t lowr, const rci_t lowc, const rci_t highr, const rci_t highc) { + printf("submatrix: m: %4d, n: %4d, (%4d, %4d, %4d, %4d)", m, n, lowr, lowc, highr, highc); + assert(highr-lowr > 0); + assert(highc-lowc > 0); + mzd_t *M = mzd_init(m, n); + mzd_randomize(M); + mzd_t *S = mzd_init(highr-lowr, highc-lowc); + mzd_submatrix(S, M, lowr, lowc, highr, highc); + int ret = 0; + for(rci_t i=0; i