Skip to content

Commit aea99aa

Browse files
committed
Replace various sprintf calls with snprintf calls
1 parent ab18167 commit aea99aa

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

code/tools/asm/cmdlib.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void ExpandWildcards( int *argc, char ***argv )
8888

8989
do
9090
{
91-
sprintf (filename, "%s%s", filebase, fileinfo.name);
91+
snprintf (filename, sizeof(filename), "%s%s", filebase, fileinfo.name);
9292
ex_argv[ex_argc++] = copystring (filename);
9393
} while (_findnext( handle, &fileinfo ) != -1);
9494

@@ -126,7 +126,7 @@ void Error( const char *error, ... )
126126
vsprintf (text, error,argptr);
127127
va_end (argptr);
128128

129-
sprintf (text2, "%s\nGetLastError() = %i", text, err);
129+
snprintf (text2, sizeof(text2), "%s\nGetLastError() = %i", text, err);
130130
MessageBox(NULL, text2, "Error", 0 /* MB_OK */ );
131131

132132
exit (1);
@@ -318,7 +318,7 @@ char *ExpandPath (const char *path)
318318
strcpy( full, path );
319319
return full;
320320
}
321-
sprintf (full, "%s%s", qdir, path);
321+
snprintf (full, sizeof(full), "%s%s", qdir, path);
322322
return full;
323323
}
324324

@@ -331,7 +331,7 @@ char *ExpandGamePath (const char *path)
331331
strcpy( full, path );
332332
return full;
333333
}
334-
sprintf (full, "%s%s", gamedir, path);
334+
snprintf (full, sizeof(full), "%s%s", gamedir, path);
335335
return full;
336336
}
337337

@@ -344,7 +344,7 @@ char *ExpandPathAndArchive (const char *path)
344344

345345
if (archive)
346346
{
347-
sprintf (archivename, "%s/%s", archivedir, path);
347+
snprintf (archivename, sizeof(archivename), "%s/%s", archivedir, path);
348348
QCopyFile (expanded, archivename);
349349
}
350350
return expanded;

code/tools/asm/q3asm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static void DefineSymbol( char *sym, int value ) {
546546

547547
// add the file prefix to local symbols to guarantee unique
548548
if ( sym[0] == '$' ) {
549-
sprintf( expanded, "%s_%i", sym, currentFileIndex );
549+
snprintf( expanded, sizeof(expanded), "%s_%i", sym, currentFileIndex );
550550
sym = expanded;
551551
}
552552

@@ -602,7 +602,7 @@ static int LookupSymbol( char *sym ) {
602602

603603
// add the file prefix to local symbols to guarantee unique
604604
if ( sym[0] == '$' ) {
605-
sprintf( expanded, "%s_%i", sym, currentFileIndex );
605+
snprintf( expanded, sizeof(expanded), "%s_%i", sym, currentFileIndex );
606606
sym = expanded;
607607
}
608608

code/tools/lcc/etc/lcc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static char *exists(char *name) {
437437
b = b->link;
438438
if (b->str[0]) {
439439
char buf[1024];
440-
sprintf(buf, "%s/%s", b->str, name);
440+
snprintf(buf, sizeof(buf), "%s/%s", b->str, name);
441441
if (access(buf, 4) == 0)
442442
return strsave(buf);
443443
} else if (access(name, 4) == 0)

code/tools/lcc/src/output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void vfprint(FILE *f, char *bp, const char *fmt, va_list ap) {
8080
static char format[] = "%f";
8181
char buf[128];
8282
format[1] = *fmt;
83-
sprintf(buf, format, va_arg(ap, double));
83+
snprintf(buf, sizeof(buf), format, va_arg(ap, double));
8484
bp = outs(buf, f, bp);
8585
}
8686
; break;

0 commit comments

Comments
 (0)