Avoid truncating filenames with snprintf().

This commit is contained in:
Tim J. Robbins 2002-06-29 05:31:26 +00:00
parent 88485b4a2f
commit e12c2e18a5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=99024

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