From: utzoo!henry
Newsgroups: net.bugs.v7
Title: basename(1) bug 
Article-I.D.: utzoo.2484
Posted: Tue Sep 21 19:29:44 1982
Received: Tue Sep 21 19:29:44 1982

The V7 basename(1) has a minor bug:  if the first argument is actually
a suffix of the second (e.g. "basename c .c"), basename will yield a
null string instead of the first argument.  The simplest fix is to change
the lines

	while(p1>p2 && p3>argv[2])
		if(*--p3 != *--p1)

to
	while(p3>argv[2])
		if(p1 <= p2 && *--p3 != *--p1)

which aborts the scan if it hits the beginning of the first argument
before hitting the beginning of the suffix.