# [Gretl-devel] numerical_hessian

Olivier Ga ogaca42 at gmail.com
Wed May 4 15:53:24 EDT 2011

Hello everyone,

I do not know if it is the right place to ask this question. Let me
know if it is not the case.

I use the arma function under linux and sun solaris.

On some dataset (not all), I have the following problem on sun solaris:
numerical_hessian: 1st derivative: criterion = NA for theta[1] = -0.500583"

Valgrind has detected no problem on linux, by purify has the following error:

Frame pointer 0xffbfdca0
Address 0xffbfdca0 is 0 bytes above stack pointer in function
kalman_arma_finish.
SBR: Stack array bounds read (36 times)
This is occurring while in:
numerical_hessian [libgretl-1.0.so.0]
kalman_arma_finish [arma.so]
kalman_arma [arma.so]
arma_model [arma.so]
arma [libgretl-1.0.so.0]

I watched quickly the numerical_hessian function and saw a strange line

#define RSTEPS 4

gretl_matrix *numerical_hessian (const double *b, int n,
BFGS_CRIT_FUNC func,
void *data, int *err)
{
...
double Dx[RSTEPS];
double Hx[RSTEPS];
...
int r = RSTEPS;      /* number of Richardson steps */
...
...
for (m=0; m<r-1; m++) {
for (k=0; k<r-m; k++) {
==>                         Dx[k] = (Dx[k+1] * p4m - Dx[k]) / (p4m - 1);
==>                         Hx[k] = (Hx[k+1] * p4m - Hx[k]) / (p4m - 1);
}
p4m *= 4;
}
...
}

In the previous lines, if m = 0, k will be equal to r - 1 at the end
of the loop.
So k+1 = (r - 1) + 1 = r = 4 which is not legal in Dx[k+1].

I am not a specialist in mathematical so my question is: "It is a true
bug or there is something I missed" ?

The version used is 1.9.1 but the lines are the same in the 1.9.5.

I cannot have access to the code or the data at the moment.