Currently not logged in. main | wiki | tasks | examples | forums | privacy | login

several seg-faults in fits_mask_scan_horizontal in fitsmask.c ( trfried | 2014 march 29., sat - 00:19 )

Briefly, both of the while() loops in this function are of the form:
while (foo[j] && j<sx) j++;
This causes seg-faults because foo[j] is evaluated *before* j<sx is checked. Reversing the order of the operands to "&&" fixes these.
However, the line:
pmv=(line[j]&FITS_MASK_MAX);
also seg-faults because the preceding while() loop can terminate on the j<sx condition, leaving j one too large for the "line" array. This one I don't know how to fix because I really don't know what the subsequent code is trying to do.
Terry


link
( trfried | 2014 august 24., sun - 20:59 ) hide
To fix the seg-fault for the line:
pmv=(line[j]&FITS_MASK_MAX);
as reported in the previous post, it is only necessary to terminate the for() loop when j hits the sx limit. I did this by simply skipping the remainder of the for() loop in the failing condition and allowing the for() itself to terminate execution normally. All of the seg-faults are cured in the following context diff.
Terry
*** fitsmask.c.dist Wed Aug 5 02:29:15 2009 --- fitsmask.c Sun Aug 24 11:50:37 2014 *************** *** 210,219 **** for ( i=0 ; i<sy ; i++ ) { line=mask; for ( j=0 ; j<sx ; ) ! { while ( ! line[j] && j<sx ) j++; oj=j; pmv=(line[j]&FITS_MASK_MAX); ! while ( (line[j]&FITS_MASK_MAX)==pmv && j<sx ) j++; nj=j-oj; if ( nj>0 ) { if ( nblock>=nablock ) --- 210,221 ---- for ( i=0 ; i<sy ; i++ ) { line=mask; for ( j=0 ; j<sx ; ) ! { while ( j<sx && (! line[j]) ) j++; ! if ( j>=sx ) ! continue; oj=j; pmv=(line[j]&FITS_MASK_MAX); ! while ( j<sx && (line[j]&FITS_MASK_MAX)==pmv ) j++; nj=j-oj; if ( nj>0 ) { if ( nblock>=nablock )