Path: utzoo!attcan!uunet!mcvax!hp4nl!eutrc3!wzv!wietse From: wietse@wzv.UUCP (Wietse Z. Venema) Newsgroups: comp.sources.bugs Subject: Re: cdiff 1.1 patch #4 (minor bug & fix) Message-ID: <177@wzv.UUCP> Date: 7 Jan 89 12:57:26 GMT References: <3843@jpl-devvax.JPL.NASA.GOV> Reply-To: wietse@wzv.UUCP (Wietse Z. Venema) Organization: Eindhoven University of Technology, The Netherlands Lines: 67 In article <3843@jpl-devvax.JPL.NASA.GOV> lwall@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@eutrc3.uucp | Eindhoven University of Technology work: wswietse@heitue5.bitnet | Mathematics and Computing Science home: wietse@wzv.uucp | 5600 MB Eindhoven, The Netherlands