Replace various sprintf calls with snprintf calls

This commit is contained in:
Tim Angus 2025-06-19 20:53:21 +01:00
parent ab18167a09
commit aea99aa3a3
4 changed files with 9 additions and 9 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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)

View File

@ -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;