[comp.bugs.sys5] bug in "lint" pass 2

gwyn@smoke.BRL.MIL (Doug Gwyn) (11/25/89)

I found out why the SVR2 version of "lint" would, when fed code like

foo.c:
	#include "hdr.h"
	...
bar.c:
	#include "hdr.h"
	...
hdr.h:
	extern void XxxxxxxxY();
	extern void XxxxxxxxZ();

produce a warning like

	hdr.h (as included in foo.c):
	(2)  warning: `XxxxxxxxY' may be indistinguishable from `XxxxxxxxY'
	due to internal name truncation

instead of the expected

	hdr.h (as included in foo.c):
	(2)  warning: `XxxxxxxxY' may be indistinguishable from `XxxxxxxxZ'
	due to internal name truncation

The problem was that the function in "lint" source file lerror2.c named
gethstr() returned a pointer to an internal static character buffer, so
the second time it was called the new string (internally known as name1)
would overwrite the previous one (known as name2) and the printf() would
format the message using two pointers to the same static buffer, which
contained only the second string read.

This is easily fixed by giving gethstr() an integer argument which would
be 0 or 1 to select between an array of two internal buffers, and invoke
it with different arguments for the two strings needed for the printf().
I had to change about 7 lines of code to implement this fix.  They should
be obvious to anyone who is competent to make changes to system code.

I don't know whether later releases of UNIX System V have the same bug.