Martijn van Duren:

> Wouldn't the following diff be a little simpler?

Yes, it would.  
Should dirbuf be static like oldfname and tmpfname?

Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/sed/main.c,v
retrieving revision 1.40
diff -u -p -r1.40 main.c
--- main.c      8 Dec 2018 23:11:24 -0000       1.40
+++ main.c      11 Oct 2020 15:08:29 -0000
@@ -96,6 +96,7 @@ const char *fname;            /* File name. */
 const char *outfname;          /* Output file name */
 static char oldfname[PATH_MAX];        /* Old file name (for in-place editing) 
*/
 static char tmpfname[PATH_MAX];        /* Temporary file name (for in-place 
editing) */
+static char dirbuf[PATH_MAX];  /* Temporary path name (for dirname(3)) */
 char *inplace;                 /* Inplace edit file extension */
 u_long linenum;
 
@@ -397,8 +398,9 @@ mf_fgets(SPACE *sp, enum e_spflag spflag
                                if (len > sizeof(oldfname))
                                        error(FATAL, "%s: name too long", 
fname);
                        }
-                       len = snprintf(tmpfname, sizeof(tmpfname), 
"%s/sedXXXXXXXXXX",
-                           dirname(fname));
+                       strlcpy(dirbuf, fname, sizeof(dirbuf));
+                       len = snprintf(tmpfname, sizeof(tmpfname),
+                           "%s/sedXXXXXXXXXX", dirname(dirbuf));
                        if (len >= sizeof(tmpfname))
                                error(FATAL, "%s: name too long", fname);
                        if ((fd = mkstemp(tmpfname)) == -1)
-- 
Christian "naddy" Weisgerber                          na...@mips.inka.de

Reply via email to