basename(1) bug

utzoo!henry utzoo!henry
Tue Sep 21 19:29:44 AEST 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.



More information about the Net.bugs.v7 mailing list