From aea99aa3a3d9cd123d39c51b9fef1e33bf77fa58 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Thu, 19 Jun 2025 20:53:21 +0100 Subject: [PATCH] Replace various sprintf calls with snprintf calls --- code/tools/asm/cmdlib.c | 10 +++++----- code/tools/asm/q3asm.c | 4 ++-- code/tools/lcc/etc/lcc.c | 2 +- code/tools/lcc/src/output.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/tools/asm/cmdlib.c b/code/tools/asm/cmdlib.c index 7d79e2c5..5fa1c31a 100644 --- a/code/tools/asm/cmdlib.c +++ b/code/tools/asm/cmdlib.c @@ -88,7 +88,7 @@ void ExpandWildcards( int *argc, char ***argv ) do { - sprintf (filename, "%s%s", filebase, fileinfo.name); + snprintf (filename, sizeof(filename), "%s%s", filebase, fileinfo.name); ex_argv[ex_argc++] = copystring (filename); } while (_findnext( handle, &fileinfo ) != -1); @@ -126,7 +126,7 @@ void Error( const char *error, ... ) vsprintf (text, error,argptr); va_end (argptr); - sprintf (text2, "%s\nGetLastError() = %i", text, err); + snprintf (text2, sizeof(text2), "%s\nGetLastError() = %i", text, err); MessageBox(NULL, text2, "Error", 0 /* MB_OK */ ); exit (1); @@ -318,7 +318,7 @@ char *ExpandPath (const char *path) strcpy( full, path ); return full; } - sprintf (full, "%s%s", qdir, path); + snprintf (full, sizeof(full), "%s%s", qdir, path); return full; } @@ -331,7 +331,7 @@ char *ExpandGamePath (const char *path) strcpy( full, path ); return full; } - sprintf (full, "%s%s", gamedir, path); + snprintf (full, sizeof(full), "%s%s", gamedir, path); return full; } @@ -344,7 +344,7 @@ char *ExpandPathAndArchive (const char *path) if (archive) { - sprintf (archivename, "%s/%s", archivedir, path); + snprintf (archivename, sizeof(archivename), "%s/%s", archivedir, path); QCopyFile (expanded, archivename); } return expanded; diff --git a/code/tools/asm/q3asm.c b/code/tools/asm/q3asm.c index c4e1413d..bf6efd66 100644 --- a/code/tools/asm/q3asm.c +++ b/code/tools/asm/q3asm.c @@ -546,7 +546,7 @@ static void DefineSymbol( char *sym, int value ) { // add the file prefix to local symbols to guarantee unique if ( sym[0] == '$' ) { - sprintf( expanded, "%s_%i", sym, currentFileIndex ); + snprintf( expanded, sizeof(expanded), "%s_%i", sym, currentFileIndex ); sym = expanded; } @@ -602,7 +602,7 @@ static int LookupSymbol( char *sym ) { // add the file prefix to local symbols to guarantee unique if ( sym[0] == '$' ) { - sprintf( expanded, "%s_%i", sym, currentFileIndex ); + snprintf( expanded, sizeof(expanded), "%s_%i", sym, currentFileIndex ); sym = expanded; } diff --git a/code/tools/lcc/etc/lcc.c b/code/tools/lcc/etc/lcc.c index a12799b6..1ff51c59 100644 --- a/code/tools/lcc/etc/lcc.c +++ b/code/tools/lcc/etc/lcc.c @@ -437,7 +437,7 @@ static char *exists(char *name) { b = b->link; if (b->str[0]) { char buf[1024]; - sprintf(buf, "%s/%s", b->str, name); + snprintf(buf, sizeof(buf), "%s/%s", b->str, name); if (access(buf, 4) == 0) return strsave(buf); } else if (access(name, 4) == 0) diff --git a/code/tools/lcc/src/output.c b/code/tools/lcc/src/output.c index a9c93e79..d68f0e3c 100644 --- a/code/tools/lcc/src/output.c +++ b/code/tools/lcc/src/output.c @@ -80,7 +80,7 @@ void vfprint(FILE *f, char *bp, const char *fmt, va_list ap) { static char format[] = "%f"; char buf[128]; format[1] = *fmt; - sprintf(buf, format, va_arg(ap, double)); + snprintf(buf, sizeof(buf), format, va_arg(ap, double)); bp = outs(buf, f, bp); } ; break;