uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 9fcb0c335bd74e1d1d4d09a74d8fdff9c2eedc6c
parent 0d242d704e69a778f9edbcfa96ae3156ff6cda4c
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Mon, 10 Jan 2022 11:35:45 +0000

Remove use of snprintf.

Diffstat:
Msrc/devices/file.c | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/devices/file.c b/src/devices/file.c @@ -13,8 +13,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -#define _POSIX_C_SOURCE 200809L - #include <stdio.h> #include <dirent.h> #include <string.h> @@ -53,13 +51,13 @@ get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int f if(len < strlen(basename) + 7) return 0; if(stat(pathname, &st)) - return fail_nonzero ? snprintf(p, len, "!!!! %s\n", basename) : 0; + return fail_nonzero ? sprintf(p, "!!!! %s\n", basename) : 0; else if(S_ISDIR(st.st_mode)) - return snprintf(p, len, "---- %s\n", basename); + return sprintf(p, "---- %s\n", basename); else if(st.st_size < 0x10000) - return snprintf(p, len, "%04x %s\n", (unsigned int)st.st_size, basename); + return sprintf(p, "%04x %s\n", (unsigned int)st.st_size, basename); else - return snprintf(p, len, "???? %s\n", basename); + return sprintf(p, "???? %s\n", basename); } static Uint16 @@ -72,7 +70,10 @@ file_read_dir(char *dest, Uint16 len) Uint16 n; if(de->d_name[0] == '.' && de->d_name[1] == '\0') continue; - snprintf(pathname, sizeof(pathname), "%s/%s", current_filename, de->d_name); + if(strlen(current_filename) + 1 + strlen(de->d_name) < sizeof(pathname)) + sprintf(pathname, "%s/%s", current_filename, de->d_name); + else + pathname[0] = '\0'; n = get_entry(p, len, pathname, de->d_name, 1); if(!n) break; p += n;