Bug in "iface" get_string()

Barton E. Schaefer schaefer at ogcvax.UUCP
Thu Feb 25 05:45:08 AEST 1988


Description:
	Line-kill with the delete key decrements the index too often,
	resulting in a segmentation fault.

Repeat-by:
	Compile the default test case and run.  Type 'd' until asked to
	enter your name.  Type a string (no newline), then hit DEL several
	times.  Note that the first character typed is never erased.  Hit
	return.  A segmentation fault usually results.

Fix:
	Remove the initial decrement in the for-loop in the DEL case in
	function get_string(), file "io.c".  Diff follows, so you can feed
	this article to patch:

*** io.c.orig	Wed Feb 24 11:24:32 1988
--- io.c	Wed Feb 24 11:31:13 1988
***************
*** 20,26 ****
  			}
  			break;
  		case 127: /* DEL */
! 			for (i--; i > 0; i--) {
  				if (str[i-1] < 32 || str[i-1] == 127) printf("\b \b");
  				printf("\b \b");
  			}
--- 20,26 ----
  			}
  			break;
  		case 127: /* DEL */
! 			for (; i > 0; i--) {
  				if (str[i-1] < 32 || str[i-1] == 127) printf("\b \b");
  				printf("\b \b");
  			}
-- 
Bart Schaefer			CSNET:	schaefer at cse.ogc.edu
				UUCP:	...{tektronix,verdix}!ogcvax!schaefer
"You can lead a yak to water, but you can't teach an old dog to make a silk
purse out of a pig in a poke."			-- Opus



More information about the Comp.sources.bugs mailing list