From d25b9c0f373a169709ec1a2c3a53ee807a2bb083 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sat, 10 Oct 2020 00:01:46 -0400 Subject: Use dynamically allocated string in struct io_file Avoid using fixed-size buffers and strncpy(). Signed-off-by: Lukas Fleischer --- src/calcurse.h | 2 +- src/io.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/calcurse.h b/src/calcurse.h index 7f03b68..763264d 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -510,7 +510,7 @@ struct notify_app { struct io_file { FILE *fd; - char name[BUFSIZ]; + char *name; }; /* Available keys. */ diff --git a/src/io.c b/src/io.c index 66f5a95..43c9b28 100644 --- a/src/io.c +++ b/src/io.c @@ -1396,7 +1396,7 @@ struct io_file *io_log_init(void) ERROR_MSG(_("Warning: could not create temporary log file, Aborting...")); goto error; } - strncpy(log->name, logname, sizeof(log->name)); + log->name = mem_strdup(logname); log->fd = fopen(log->name, "w"); if (log->fd == NULL) { ERROR_MSG(_("Warning: could not open temporary log file, Aborting...")); @@ -1446,6 +1446,7 @@ void io_log_free(struct io_file *log) EXIT_IF(unlink(log->name) != 0, _("Warning: could not erase temporary log file %s, Aborting..."), log->name); + mem_free(log->name); mem_free(log); } -- cgit v1.2.3-70-g09d2