[comp.lang.perl] Bug in form.c

worley@compass.com (Dale Worley) (12/28/90)

The code I wrote for numeric formats has a serious bug:  If you use a
numeric field that starts with '^' (blank if undefined), the field
will not be blanked correctly and will sometimes fill the rest of the
line with garbage.  The fix is to compute the size of the field before
checking whether the field should be blanked:

*** form.c.orig	Wed Dec 26 15:55:39 1990
--- form.c	Wed Dec 26 15:55:50 1990
***************
*** 289,294 ****
--- 289,296 ----
  
  	    (void)eval(fcmd->f_expr,G_SCALAR,sp);
  	    str = stack->ary_array[sp+1];
+ 	    size = fcmd->f_size;
+ 	    CHKLEN(size);
  	    /* If the field is marked with ^ and the value is undefined,
  	       blank it out. */
  	    if ((fcmd->f_flags & FC_CHOP) && !str->str_pok && !str->str_nok) {
***************
*** 299,306 ****
  		break;
  	    }
  	    value = str_gnum(str);
- 	    size = fcmd->f_size;
- 	    CHKLEN(size);
  	    if (fcmd->f_flags & FC_DP) {
  		sprintf(d, "%#*.*f", size, fcmd->f_decimals, value);
  	    } else {
--- 301,306 ----

Dale

Dale Worley		Compass, Inc.			worley@compass.com
--
Those who will be able to conquer software will be able to
conquer the world.  -- Tadahiro Sekimoto, President, NEC Corp.