{
static const char *fmt = "%u.%u.%u.%u";
char tmp[sizeof "255.255.255.255"];
+ size_t len;
- if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size)
- {
+ len = snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3]);
+ if (len >= size) {
errno = ENOSPC;
return (NULL);
}
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
struct { int base, len; } best, cur;
unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
- int i;
+ int i, inc;
/*
* Preprocess:
/* Is this address an encapsulated IPv4? */
if (i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
- if (!inet_ntop4(src+12, tp,
- sizeof tmp - (tp - tmp)))
+ if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
return (NULL);
tp += strlen(tp);
break;
}
- tp += sprintf(tp, "%x", words[i]);
+ inc = snprintf(tp, 5, "%x", words[i]);
+ assert(inc < 5);
+ tp += inc;
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) ==