Handle snprintf() returning -1.

MFC after:	2 weeks
This commit is contained in:
Brian Somers 2001-08-20 12:56:45 +00:00
parent 6dac8ac9e5
commit 327e849ae1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=81976
3 changed files with 9 additions and 5 deletions

View file

@ -650,6 +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 (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 >= sizeof(cresult))
if (l == -1 || l >= sizeof(cresult))
return NULL;
if (strlcat(buf, cresult, bufsiz) >= bufsiz)
return NULL; /*result overrun*/

View file

@ -310,7 +310,7 @@ routename(sa)
static char line[MAXHOSTNAMELEN + 1];
struct hostent *hp;
static char domain[MAXHOSTNAMELEN + 1];
static int first = 1;
static int first = 1, n;
#ifdef NS
char *ns_print();
#endif
@ -408,7 +408,8 @@ routename(sa)
char *cpe = line + sizeof(line);
while (++s < slim && cp < cpe) /* start with sa->sa_data */
cp += snprintf(cp, cpe - cp, " %x", *s);
if ((n = snprintf(cp, cpe - cp, " %x", *s)) > 0)
cp += n;
break;
}
}
@ -428,7 +429,7 @@ netname(sa)
struct netent *np = 0;
u_long net, mask;
register u_long i;
int subnetshift;
int n, subnetshift;
#ifdef NS
char *ns_print();
#endif
@ -543,7 +544,8 @@ netname(sa)
char *cpe = line + sizeof(line);
while (s < slim && cp < cpe)
cp += snprintf(cp, cpe - cp, " %x", *s++);
if ((n = snprintf(cp, cpe - cp, " %x", *s++)) > 0)
cp += n;
break;
}
}