ed: Fix error introduced in b19d708

This patch introduced init() function, which removed the initialization
code of savfname in doread, but this is incorrect, because savfname
can be initialized with a r command if savfname is empty.
This commit is contained in:
Roberto E. Vargas Caballero 2016-01-01 17:40:34 +01:00 committed by sin
parent 6630bd97cf
commit cf0a0fc940

19
ed.c
View File

@ -702,7 +702,7 @@ chkprint(int flag)
} }
static char * static char *
getfname(void) getfname(char comm)
{ {
int c; int c;
char *bp; char *bp;
@ -721,6 +721,8 @@ getfname(void)
error("file name too long"); error("file name too long");
} else { } else {
*bp = '\0'; *bp = '\0';
if (savfname[0] == '\0' || comm == 'e' || comm == 'f')
strcpy(savfname, fname);
return fname; return fname;
} }
return NULL; /* not reached */ return NULL; /* not reached */
@ -1015,7 +1017,7 @@ subst(int nth)
static void static void
docmd(void) docmd(void)
{ {
char *s, cmd; char cmd;
int rep = 0, c, line3, num, trunc; int rep = 0, c, line3, num, trunc;
repeat: repeat:
@ -1073,13 +1075,13 @@ repeat:
trunc = 1; trunc = 1;
case 'W': case 'W':
deflines(nextln(0), lastln); deflines(nextln(0), lastln);
dowrite(getfname(), trunc); dowrite(getfname(cmd), trunc);
break; break;
case 'r': case 'r':
if (nlines > 1) if (nlines > 1)
goto bad_address; goto bad_address;
deflines(lastln, lastln); deflines(lastln, lastln);
doread(getfname()); doread(getfname(cmd));
break; break;
case 'd': case 'd':
chkprint(1); chkprint(1);
@ -1190,10 +1192,11 @@ repeat:
case 'f': case 'f':
if (nlines > 0) if (nlines > 0)
goto unexpected; goto unexpected;
if (!strcmp(s = getfname(), savfname)) if (back(input()) != '\n')
puts(savfname); getfname(cmd);
else else
strcpy(savfname, s); puts(savfname);
chkprint(0);
break; break;
case 'E': case 'E':
modflag = 0; modflag = 0;
@ -1202,7 +1205,7 @@ repeat:
goto unexpected; goto unexpected;
if (modflag) if (modflag)
goto modified; goto modified;
strcpy(savfname, getfname()); getfname(cmd);
setscratch(); setscratch();
deflines(curln, curln); deflines(curln, curln);
doread(savfname); doread(savfname);