nlopt icon indicating copy to clipboard operation
nlopt copied to clipboard

SLSQP fc2 array clean up

Open mhunter1 opened this issue 4 years ago • 2 comments

Hi All,

I'm the developer for an R package that uses SLSQP, and the CRAN team has taken issue with a warning within SLSQP.

  slsqp.c:862:5: warning: array subscript -1 is outside array bounds of
‘double[1]’ [-Warray-bounds]

I cannot replicate the compiler warning, but it appears to be around here: https://github.com/stevengj/nlopt/blob/master/src/algs/slsqp/slsqp.c#L859:L862 . It is likely caused by the creation of slsqp.c from the original FORTRAN via f2c, and might just be a false positive. Is there anything that can be done on the NLopt side?

mhunter1 avatar Mar 07 '21 17:03 mhunter1

f2c offsets all of the array pointers by -1 so that it can use the original 1-based indexing in C. If the compiler is complaining about subtracting 1 from the pointers then this is (a) valid C, (b) harmless, and (c) very painful to change (we'd have to go through every array access to shift the indices by 1).

stevengj avatar Mar 10 '21 01:03 stevengj

I agree with you 100% and I made similar arguments to folks at CRAN. They did not agree. FWIW, I think this change was sufficient to appease them: https://github.com/mhunter1/dynr/commit/58e1ba91f05f04eeff6770a7d57d87457a32b22e

Feel free to close this issue.

mhunter1 avatar Mar 10 '21 19:03 mhunter1