mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Prefer snprintf to strncpy when outputting C strings
strncpy is designed to output to fixed‐width buffers, not C strings (hence its weird null termination behavior). In this case it happens to work correctly due to the length check but, for style reasons, I would rather use snprintf. Especially in this case, where it shortens the code a bit.
This commit is contained in:
committed by
Antonio Niño Díaz
parent
a7dc86001c
commit
abeca2d305
@@ -225,12 +225,8 @@ void fstk_AddIncludePath(char *s)
|
|||||||
if (NextIncPath == MAXINCPATHS)
|
if (NextIncPath == MAXINCPATHS)
|
||||||
fatalerror("Too many include directories passed from command line");
|
fatalerror("Too many include directories passed from command line");
|
||||||
|
|
||||||
if (strlen(s) >= sizeof(IncludePaths[0]))
|
if (snprintf(IncludePaths[NextIncPath++], _MAX_PATH, "%s", s) >= _MAX_PATH)
|
||||||
fatalerror("Include path too long '%s'", s);
|
fatalerror("Include path too long '%s'", s);
|
||||||
|
|
||||||
strncpy(IncludePaths[NextIncPath], s, sizeof(IncludePaths[0]));
|
|
||||||
|
|
||||||
NextIncPath++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *fstk_FindFile(char *fname)
|
FILE *fstk_FindFile(char *fname)
|
||||||
|
|||||||
Reference in New Issue
Block a user