cdiff 1.1 patch #4 (minor bug & fix)

Wietse Z. Venema wietse at wzv.UUCP
Sat Jan 7 22:57:26 AEST 1989


In article <3843 at jpl-devvax.JPL.NASA.GOV> lwall at jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
>
>	Now one or the other of the filenames can be a directory
>	holding a different version by the same name.

The algorithm for filename construction is a bit naive:

	$ cp /etc/passwd /tmp
	$ ./cdiff /etc/passwd /tmp
	Can't open /tmp//etc/passwd

The fix (see below) is relatively simple.  I also found that cdiff does
not check whether both file arguments are directories:

	$ ./cdiff /etc /tmp
	Can't open /etc//tmp

Since the bare diff(1) command suffers from the same problem (on S5R2
systems at least) no attempt was made to remove this feature from the
cdiff source.

In the following fix you may want to substitute rindex() for the
strrchr() call.
					    Wietse Venema

*** cdiff.c.bug	Sat Jan  7 12:31:23 1989
--- cdiff.c	Sat Jan  7 12:31:23 1989
***************
*** 103,109 ****
  
      stat(old,&statbuf);
      if((statbuf.st_mode&S_IFMT) == S_IFDIR) {
! 	sprintf(buf, "%s/%s", old, new);
  	old = buf;
  	stat(old,&statbuf);
      }
--- 103,110 ----
  
      stat(old,&statbuf);
      if((statbuf.st_mode&S_IFMT) == S_IFDIR) {
! 	char *strrchr(), *kludge = strrchr(new,'/');
! 	sprintf(buf, "%s/%s", old, kludge ? kludge+1 : new);
  	old = buf;
  	stat(old,&statbuf);
      }
***************
*** 116,122 ****
  
      stat(new,&statbuf);
      if((statbuf.st_mode&S_IFMT) == S_IFDIR) {
! 	sprintf(buf, "%s/%s", new, old);
  	new = buf;
  	stat(new,&statbuf);
      }
--- 117,124 ----
  
      stat(new,&statbuf);
      if((statbuf.st_mode&S_IFMT) == S_IFDIR) {
! 	char *strrchr(), *kludge = strrchr(old,'/');
! 	sprintf(buf, "%s/%s", new, kludge ? kludge+1 : old);
  	new = buf;
  	stat(new,&statbuf);
      }
-- 
work:	wswietse at eutrc3.uucp	| Eindhoven University of Technology
work:	wswietse at heitue5.bitnet	| Mathematics and Computing Science
home:	wietse at wzv.uucp		| 5600 MB Eindhoven, The Netherlands



More information about the Comp.sources.bugs mailing list