commit ff26d4769e3b190bbc051526359a9235803b51af
parent 158cf998967695f2eeefd2550354cc9994568a88
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 3 Dec 2015 13:00:29 +0100
Change sprintf to snprintf in sighup()
It simplifies the code in this case,a nd we avoid calling to
strlen.
Diffstat:
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/ed.c b/ed.c
@@ -984,6 +984,7 @@ sigintr(int n)
static void
sighup(int dummy)
{
+ int n;
char *home = getenv("HOME"), fname[FILENAME_MAX];
if (modflag) {
@@ -992,11 +993,10 @@ sighup(int dummy)
if (!setjmp(savesp)) {
dowrite("ed.hup", 1);
} else if (home && !setjmp(savesp)) {
- size_t len = strlen(home) + sizeof("ed.hup") + 1;
- if (len < FILENAME_MAX) {
- sprintf(fname, "%s/%s", home, "ed.hup");
+ n = snprintf(fname,
+ sizeof(fname), "%s/%s", home, "ed.hup");
+ if (n < sizeof(fname) && n > 0)
dowrite(fname, 1);
- }
}
}
exit(1);