summaryrefslogtreecommitdiff
path: root/sci-libs/m4ri/files/m4ri-20200115-memory_violation.patch
diff options
context:
space:
mode:
Diffstat (limited to 'sci-libs/m4ri/files/m4ri-20200115-memory_violation.patch')
-rw-r--r--sci-libs/m4ri/files/m4ri-20200115-memory_violation.patch87
1 files changed, 87 insertions, 0 deletions
diff --git a/sci-libs/m4ri/files/m4ri-20200115-memory_violation.patch b/sci-libs/m4ri/files/m4ri-20200115-memory_violation.patch
new file mode 100644
index 000000000000..b74be3b4bf8f
--- /dev/null
+++ b/sci-libs/m4ri/files/m4ri-20200115-memory_violation.patch
@@ -0,0 +1,87 @@
+From e2fb0dcb70a97972fa1576a528cb01458f57a85d Mon Sep 17 00:00:00 2001
+From: "Martin R. Albrecht" <martinralbrecht@googlemail.com>
+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; i<nrows; i++) {
+- for(j=0; j+m4ri_radix<=ncols; j+=m4ri_radix)
++ for(j=0; j+m4ri_radix<ncols; j+=m4ri_radix)
+ S->rows[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<highr-lowr; i++) {
++ for(rci_t j=0; j<highc-lowc; j++) {
++ ret += (mzd_read_bit(M, lowr+i, lowc+j) ^ mzd_read_bit(S, i, j));
++ }
++ }
++
++ mzd_free(M);
++ mzd_free(S);
++
++ if(ret==0) {
++ printf(" ... passed\n");
++ } else {
++ printf(" ... FAILED\n");
++ }
++ return ret;
++}
+
+ int main(int argc, char *argv[]) {
+ int status = 0;
+@@ -99,6 +124,23 @@ int main(int argc, char *argv[]) {
+ status += test_png(126,12);
+ status += test_png(128,200);
+
++ status += test_submatrix(2, 127, 1, 1, 2, 127);
++ status += test_submatrix(2, 128, 1, 1, 2, 128);
++ status += test_submatrix(2, 129, 1, 1, 2, 129);
++ status += test_submatrix(2, 130, 1, 1, 2, 130);
++ status += test_submatrix(2, 131, 1, 1, 2, 131);
++
++ status += test_submatrix(2, 63, 1, 1, 1, 63);
++ status += test_submatrix(2, 64, 1, 1, 1, 64);
++ status += test_submatrix(2, 65, 1, 1, 1, 65);
++ status += test_submatrix(2, 66, 1, 1, 1, 66);
++ status += test_submatrix(2, 67, 1, 1, 1, 67);
++
++ status += test_submatrix(2, 127, 1, 63, 2, 127);
++ status += test_submatrix(2, 128, 1, 64, 2, 128);
++ status += test_submatrix(2, 129, 1, 65, 2, 129);
++ status += test_submatrix(2, 130, 1, 66, 2, 130);
++
+ if (!status) {
+ printf("All tests passed.\n");
+ } else {
+--
+2.10.5
+