Skip to content
Prev 32899 / 63424 Next

Print bug for matrix(list(NA_complex_, ...))

...
...
Here is the traceback when it enters Rf_EncodeReal:
(gdb) where
#0  Rf_EncodeReal (x=nan(0x0000007a2), w=168381312, d=0, e=0, cdec=46
'.')
    at printutils.c:160
#1  0x08099aaa in Rf_PrintValueRec (s=0x9f4a4a8, env=0x9e4cc90) at
print.c:359
#2  0x0809a125 in Rf_PrintValueEnv (s=0x9f4a4a8, env=0x9e4cc90) at
print.c:956
#3  0x080584cb in Rf_ReplIteration (rho=0x9e4cc90, savestack=0,
browselevel=0,
    state=0xbffc7820) at main.c:261
#4  0x08058573 in R_ReplConsole (rho=0x9e4cc90, savestack=0,
browselevel=0)
    at main.c:306
#5  0x08058bb9 in run_Rmainloop () at main.c:967

It looks like w has a bogus value and was probably never initialized.
It is called from print.c:

    354             case CPLXSXP:
    355                 if (LENGTH(tmp) == 1) {
    356                     Rcomplex *x = COMPLEX(tmp);
    357                     formatComplex(x, 1, &wr, &dr, &er, &wi, &di,
&ei, 0);
    358                     if (ISNA(x[0].r) || ISNA(x[0].i))
    359                         snprintf(pbuf, 115, "%s",
    360                                  EncodeReal(NA_REAL, w, 0, 0,
OutDec));
    361                     else
    362                         snprintf(pbuf, 115, "%s",
EncodeComplex(x[0],
    363                         wr, dr, er, wi, di, ei, OutDec));

and I think the 'w' needs to be replaced by something reasonable for
printing "NA"
(or "NA_complex_?, I don't know all of what this code is used for).
Usually complex printing uses wr and wi, not w, so w is not initialized.