Avoid truncating filenames with snprintf().

This commit is contained in:
tjr 2002-06-29 05:31:26 +00:00
parent 2ca2fb4fa3
commit ad903dff1e

View File

@ -227,8 +227,11 @@ newfile(void)
{
FILE *fp;
snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix, (int)sufflen,
nfiles);
if (snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix,
(int)sufflen, nfiles) >= sizeof(currfile)) {
errno = ENAMETOOLONG;
err(1, NULL);
}
if ((fp = fopen(currfile, "w+")) == NULL)
err(1, "%s", currfile);
nfiles++;