From 10b832746a66850d7018093436696bcac794897f Mon Sep 17 00:00:00 2001 From: David Griffith Date: Sun, 3 Feb 2019 05:24:55 -0800 Subject: [PATCH] Rewrite last strcpy() call in ux_init.c and remove a FILENAME_MAX instance. --- src/curses/ux_init.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 19c72fc..04ea294 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -724,26 +724,28 @@ int os_storyfile_tell(FILE * fp) * that file. If found, return a pointer to that file * */ -static FILE *pathopen(const char *name, const char *p, const char *mode) +static FILE *pathopen(const char *name, const char *path, const char *mode) { FILE *fp; - char buf[FILENAME_MAX + 1]; + char *buf; char *bp, lastch; lastch = 'a'; /* makes compiler shut up */ - while (*p) { + buf = malloc(strlen(path) + strlen(name) + 1); + + while (*path) { bp = buf; - while (*p && *p != PATHSEP) - lastch = *bp++ = *p++; + while (*path && *path != PATHSEP) + lastch = *bp++ = *path++; if (lastch != DIRSEP) *bp++ = DIRSEP; - strcpy(bp, name); + strncpy(bp, name, strlen(path) + strlen(name) + 1); if ((fp = fopen(buf, mode)) != NULL) { return fp; } - if (*p) - p++; + if (*path) + path++; } return NULL; } /* FILE *pathopen() */ -- 2.34.1