Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was an ancient bug in the parallelised
eig
andchol
code which failed to check the number of output variablesnlhs
and tries to access a pointer which does not exist.In older versions of Matlab this seems to work (the routines get a pointer to the actual data using
mxGetData
given the address of anmxArray
but never uses that pointer), but with Matlab 2023a and newer this causes a segmentation fault because the internal behaviour ofmxGetData
/ the internal definition of the opaquemxArray
class/struct has changed.Specifically, the code tries to access the output pointers array
plhs[]
which hasnlhs
elements long but the code always assumes thatnlhs
is at lease2
. Hence whennlhs=1
,plhs[1]
is a junk pointer. I suspect that in older versions of Matlab,mxGetData
just returns the input pointer plus an offset, which will work with a junk input pointer as long as no processing is done on the (junk) output. I think that in newer versions of Matlab,mxGetData
actually tries to dereference themxArray
structure to access itspr
member (the data pointer), and this will give a segfault because the input pointer is junk.The PR now checks what
nlhs
is and guards against this out-of-bounds error.