You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
static int numElements(SAFEARRAY *psa)
{
int nDims = SafeArrayGetDim(psa);
int elems = 0;
for(int i=1;i<=nDims;i++) {
long lb, ub;
SafeArrayGetLBound(psa, i, &lb);
SafeArrayGetUBound(psa, i, &ub);
elems += ub - lb + 1;
}
return elems;
}
This calculation is incorrect, as the number of elements in an mxn array is mxn, not m+n. It happens to be correct in the 1D case only, but not beyond. The effect of this is that fromXXXArray() and toXXXArray() don't work for 2D and higher.
Solution:
static int numElements(SAFEARRAY *psa)
{
int nDims = SafeArrayGetDim(psa);
int elems = 0;
for(int i=1;i<=nDims;i++) {
long lb, ub;
SafeArrayGetLBound(psa, i, &lb);
SafeArrayGetUBound(psa, i, &ub);
if (elems == 0)
elems = 1;
elems *= ub - lb + 1;
}
return elems;
}
The text was updated successfully, but these errors were encountered:
EJP286CRSKW
changed the title
Incorrect and pointless calculations in SafeArray.coo numElements()
Incorrect and pointless calculations in SafeArray.cpp numElements()
Nov 7, 2023
EJP286CRSKW
changed the title
Incorrect and pointless calculations in SafeArray.cpp numElements()
Incorrect element-count calculation in SafeArray.cpp numElements()
Dec 1, 2023
EJP286CRSKW
changed the title
Incorrect element-count calculation in SafeArray.cpp numElements()
Incorrect element-count calculation in SafeArray.cpp numElements() cause 2D and higher SafeArrays to fail
Dec 1, 2023
This calculation is incorrect, as the number of elements in an mxn array is mxn, not m+n. It happens to be correct in the 1D case only, but not beyond. The effect of this is that fromXXXArray() and toXXXArray() don't work for 2D and higher.
Solution:
The text was updated successfully, but these errors were encountered: