sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 18742eed170c03a122ddb4d63af6616145489d9a
parent 6a088a92521d4c1e01384c1183b0de27d887e9cd
Author: sin <sin@2f30.org>
Date:   Sat Jan  2 10:32:44 +0000

ed: Use snprintf() for constructing the scratch filename

Diffstat:
ed.c | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/ed.c b/ed.c @@ -328,17 +328,17 @@ clearbuf() static void setscratch() { - int k; + int r, k; char *dir; clearbuf(); clearundo(); if ((dir = getenv("TMPDIR")) == NULL) - dir = "/tmp/"; - if (strlcpy(tmpname, dir, sizeof(tmpname)) >= sizeof(tmpname)) - error("scratch file name too long"); - if (strlcat(tmpname, "ed.XXXXXX", sizeof(tmpname)) >= sizeof(tmpname)) - error("scratch file name too long"); + dir = "/tmp"; + r = snprintf(tmpname, sizeof(tmpname), "%s/%s", + dir, "ed.XXXXXX"); + if (r < 0 || (size_t)r >= sizeof(tmpname)) + error("scratch filename too long"); if ((scratch = mkstemp(tmpname)) < 0) error("failed to create scratch file"); if ((k = makeline("", NULL)))