ed: Use snprintf() for constructing the scratch filename
This commit is contained in:
parent
3300d5d47a
commit
16159a61ac
12
ed.c
12
ed.c
|
@ -328,17 +328,17 @@ clearbuf()
|
||||||
static void
|
static void
|
||||||
setscratch()
|
setscratch()
|
||||||
{
|
{
|
||||||
int k;
|
int r, k;
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
clearbuf();
|
clearbuf();
|
||||||
clearundo();
|
clearundo();
|
||||||
if ((dir = getenv("TMPDIR")) == NULL)
|
if ((dir = getenv("TMPDIR")) == NULL)
|
||||||
dir = "/tmp/";
|
dir = "/tmp";
|
||||||
if (strlcpy(tmpname, dir, sizeof(tmpname)) >= sizeof(tmpname))
|
r = snprintf(tmpname, sizeof(tmpname), "%s/%s",
|
||||||
error("scratch file name too long");
|
dir, "ed.XXXXXX");
|
||||||
if (strlcat(tmpname, "ed.XXXXXX", sizeof(tmpname)) >= sizeof(tmpname))
|
if (r < 0 || (size_t)r >= sizeof(tmpname))
|
||||||
error("scratch file name too long");
|
error("scratch filename too long");
|
||||||
if ((scratch = mkstemp(tmpname)) < 0)
|
if ((scratch = mkstemp(tmpname)) < 0)
|
||||||
error("failed to create scratch file");
|
error("failed to create scratch file");
|
||||||
if ((k = makeline("", NULL)))
|
if ((k = makeline("", NULL)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user