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:
Anthony J. Bentley
2018-01-27 01:21:23 +00:00
committed by Antonio Niño Díaz
parent a7dc86001c
commit abeca2d305

View File

@@ -225,12 +225,8 @@ void fstk_AddIncludePath(char *s)
if (NextIncPath == MAXINCPATHS)
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);
strncpy(IncludePaths[NextIncPath], s, sizeof(IncludePaths[0]));
NextIncPath++;
}
FILE *fstk_FindFile(char *fname)