2
0
Fork 0

fix: cayleyTransform memory addressing problem due to int/double pointer cast.

This commit is contained in:
Daniel Kapla 2019-12-17 20:41:57 +01:00
parent e2034c9ff6
commit 8761407cad
1 changed files with 7 additions and 2 deletions

View File

@ -942,11 +942,16 @@ mat* cayleyTransform(mat *A, mat *B, mat *C, double *workMem) {
/* Allocate row permutation array used by `dgesv` */
int *ipiv = (int*)workMem;
/* NOTE: workMem offset, NOT ipiv offset! There may be a bit space left out
* but the working memory is required elsewhere anyway. It's impotant to
* have an appropriate beginning cause if may occure the case that the
* memory addressing faily due to size differences between int and double
* leading to an illegal double* address. */
double *IpA = workMem + A->nrow;
/* Create Matrix IpA = I + A (I plus A) */
double *IpA = (double*)(ipiv + A->nrow);
memcpy(IpA, A->elem, A->nrow * A->ncol * sizeof(double));
for (i = 0; i < pp; i += A->nrow + 1) {
IpA[i] += 1.; // +1 to diagonal elements.
IpA[i] += 1.0; // +1 to diagonal elements.
}
/* Create Matrix ImA = I - A (I minus A) */