Skip to content
Prev 33561 / 63424 Next

Bug in nlm, found using sem; failure in several flavors (PR#13883)

William Dunlap wrote:
...

Mmmm... This comes from this code inside fcn()

     if (state->have_gradient) {
         g = REAL(coerceVector(getAttrib(s, install("gradient")),
                  REALSXP));
         if (state->have_hessian) {
             h = REAL(coerceVector(getAttrib(s, install("hessian")),
                                   REALSXP));
         }
     }
     FT_store(n, *f, x, g, h, state);

I suppose that if the function being optimized returns a value that has 
a "gradient" attribute, then that is being used. It is coerced to 
double; but otherwise, no questions asked.

I wonder if it would not be a good idea to at least check that 
getAttrib(....) returns something of the right length.