1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-11 09:50:12 +00:00

Handle snprintf() returning < 0 (not just -1)

MFC after:	2 weeks
This commit is contained in:
Brian Somers 2001-08-20 14:53:05 +00:00
parent cbe1d3b630
commit 9cfe90fe1f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=81980
3 changed files with 7 additions and 3 deletions

View File

@ -650,8 +650,8 @@ mkfs(pp, fsys, fi, fo)
j = snprintf(tmpbuf, sizeof(tmpbuf), " %ld%s",
fsbtodb(&sblock, cgsblock(&sblock, cylno)),
cylno < (sblock.fs_ncg-1) ? "," : "" );
if (j == -1)
j = 0;
if (j < 0)
tmpbuf[j = 0] = '\0';
if (i + j >= width) {
printf("\n");
i = 0;

View File

@ -1353,7 +1353,7 @@ dnsdecode(sp, ep, base, buf, bufsiz)
while (i-- > 0 && cp < ep) {
l = snprintf(cresult, sizeof(cresult),
isprint(*cp) ? "%c" : "\\%03o", *cp & 0xff);
if (l == -1 || l >= sizeof(cresult))
if (l < 0 || l >= sizeof(cresult))
return NULL;
if (strlcat(buf, cresult, bufsiz) >= bufsiz)
return NULL; /*result overrun*/

View File

@ -410,6 +410,8 @@ routename(sa)
while (++s < slim && cp < cpe) /* start with sa->sa_data */
if ((n = snprintf(cp, cpe - cp, " %x", *s)) > 0)
cp += n;
else
*cp = '\0';
break;
}
}
@ -546,6 +548,8 @@ netname(sa)
while (s < slim && cp < cpe)
if ((n = snprintf(cp, cpe - cp, " %x", *s++)) > 0)
cp += n;
else
*cp = '\0';
break;
}
}