ed: Use strlcpy() instead of strcpy() and other minor things
Based on contribution by Ali H. Fardan, thanks!
This commit is contained in:
parent
370e0ae675
commit
e2f886c7e2
18
ed.c
18
ed.c
@ -322,7 +322,7 @@ inject(char *s, int j)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clearbuf()
|
clearbuf(void)
|
||||||
{
|
{
|
||||||
if (scratch)
|
if (scratch)
|
||||||
close(scratch);
|
close(scratch);
|
||||||
@ -334,7 +334,7 @@ clearbuf()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setscratch()
|
setscratch(void)
|
||||||
{
|
{
|
||||||
int r, k;
|
int r, k;
|
||||||
char *dir;
|
char *dir;
|
||||||
@ -421,6 +421,7 @@ rematch(int num)
|
|||||||
lastmatch += off;
|
lastmatch += off;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +548,7 @@ invalid:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
getlst()
|
getlst(void)
|
||||||
{
|
{
|
||||||
int ln, c;
|
int ln, c;
|
||||||
|
|
||||||
@ -595,7 +596,7 @@ deflines(int def1, int def2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dowrite(char *fname, int trunc)
|
dowrite(const char *fname, int trunc)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int i, line;
|
int i, line;
|
||||||
@ -610,13 +611,14 @@ dowrite(char *fname, int trunc)
|
|||||||
curln = line2;
|
curln = line2;
|
||||||
if (fclose(fp))
|
if (fclose(fp))
|
||||||
error("input/output error");
|
error("input/output error");
|
||||||
strcpy(savfname, fname);
|
if (strlcpy(savfname, fname, sizeof(savfname)) >= sizeof(savfname))
|
||||||
|
error("file name too long");
|
||||||
modflag = 0;
|
modflag = 0;
|
||||||
curln = line;
|
curln = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
doread(char *fname)
|
doread(const char *fname)
|
||||||
{
|
{
|
||||||
size_t cnt;
|
size_t cnt;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
@ -741,9 +743,11 @@ getfname(char comm)
|
|||||||
} else {
|
} else {
|
||||||
*bp = '\0';
|
*bp = '\0';
|
||||||
if (savfname[0] == '\0' || comm == 'e' || comm == 'f')
|
if (savfname[0] == '\0' || comm == 'e' || comm == 'f')
|
||||||
strcpy(savfname, fname);
|
if (strlcpy(savfname, fname, sizeof(savfname)) >= sizeof(savfname))
|
||||||
|
error("file name too long");
|
||||||
return fname;
|
return fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL; /* not reached */
|
return NULL; /* not reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user