4.[12] bsd multiple tgetent bug (with fix) (reposting)

Arthur David Olson ado at elsie.UUCP
Sat Sep 15 08:58:33 AEST 1984


Patient--
	/usr/src/lib/libtermlib/termcap.c in 4.1bsd
	/usr/src/usr.lib/libtermlib/termcap.c in 4.2bsd

Condition--
	Calling "tgetent" multiple times can result in spurious diagnostics.

Stimulus--
	#include <stdio.h>

	main()
	{
		int	i;
		char	buf[1024];

		for (i = 1; i < 40 ; ++i)
			if (tgetent(buf, "vt100w") != 1)
				return 1;
			else	printf("okay on pass %d\n");
		return 0;
	}

	If you get an "Infinite tc= loop" diagnostic after a number of
	successful passes, you've got the bug.

Diagnosis--
	A variable named "hopcount" counts the total number of "tc=" constructs
	found in termcap entries.  Alas, hopcount counts the total number of
	"tc="s found during the life of the process.

Cure--
	We'll go for minimizing changes to existing code here.

	ed /usr/src/lib/libtermlib/termcap.c
	g/return(tnchktc/i\
	#ifdef OLDVERSION
	g/return(tnchktc/a\
	#else\
				i = tnchktc(); hopcount = 0; return i;\
	#endif
	w
	q
--
	...decvax!seismo!umcp-cs!elsie!ado	(301) 496-5688
	(DEC, VAX and Elsie are Digital Equipment Corp. and Borden's trademarks)



More information about the Comp.bugs.4bsd.ucb-fixes mailing list