Thank you for tracking this down. The gcc compiler should be capable of detecting most of this kind of bugs, but since it would produce lots of warnings and we got on one to audit those one by one, so those warnings are suppressed by the flag -Wno-maybe-uninitialized If you remove this flag, perhaps you can get all those potential bugs and check one by one. IIRC, The gcc idiom to suppress the warning if a variable is known to be initialized before use is declared by something like int nbx=nbx
On Fri, Mar 9, 2018, 4:55 AM Chris Double <chris.dou...@double.co.nz> wrote: > Running jconsole through valgrind picked up a conditional check in > jtjprx in f.c depending on an uninitialized value. > > The check occurs here: > > > https://github.com/jsoftware/jsource/blob/332c18ced323d33ae50d9551ab4d52d18e158375/jsrc/f.c#L804 > > The relevant code block being: > > case 1: > // LIT characters. Copy them. If there were boxing characters about, > copy one by one and translate if boxing chars > // No need to suppress NULs - if the result is LIT, all boxes must > have converted to LIT, and would have had NUL converted to space > if(nbx){DO(c1, x=*v++; BDC(zv,x);); if(c1<c){v+=c-c1; DDD(zv);}} > // Otherwise just move fast > > Here, nbx can be uninitialized (ie. set to a random memory value) > unless certain conditions are met with parsing. > > It is declared here: > > > https://github.com/jsoftware/jsource/blob/332c18ced323d33ae50d9551ab4d52d18e158375/jsrc/f.c#L706 > > static A jtjprx(J jt,I ieol,I maxlen,I lb,I la,A w){A y,z;B ch;C > e,eov[2],*v,x,*zu,*zv;D lba; I c,c1,h,i,j,k,lc,m,nbx,nq,p,q,r,*s,t,zn; > > and is initialized in the following line: > > > https://github.com/jsoftware/jsource/blob/332c18ced323d33ae50d9551ab4d52d18e158375/jsrc/f.c#L733 > > if(ch||AT(w)&BOX+SPARSE)zn+=nbx=countonlines(scanbdc,t,v,h,nq,c,lb,la); > > It can be demonstrated outside of valgrind by adding a print statement > just before the check in line 804 to print the value of nbx. With this > print statement in affect, here's a console session: > > $ ./bin/jconsole > 1 > nbx: -1692375296 > 1 > <1 > nbx: 24 > 1 > > $ ./bin/jconsole -lib libj-nonavx.so > 1 > nbx: 977359104 > 1 > <1 > nbx: 24 > 1 > > Note that an unboxed expression shows random uninitialized values for > nbx on each run. An expression containing the box character triggers > the initialization in line 733 and shows a reasonable value. > > The net affect of this is that the "otherwise move fast" else block in > the if loop probably never gets hit unless nbx happens to randomly > initialize to zero. > > -- > http://bluishcoder.co.nz > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm