diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-06-13 19:08:05 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-06-13 19:08:05 +0200 |
commit | ec466f65463e6bfbdf508b50cc2a60593a41b80c (patch) | |
tree | fc7290618727a3e1701c7c5dcb9d026808c2eb71 /lib/prefix.c | |
parent | Merge pull request #4502 from opensourcerouting/topotest-backward-compat (diff) | |
download | frr-ec466f65463e6bfbdf508b50cc2a60593a41b80c.tar.xz frr-ec466f65463e6bfbdf508b50cc2a60593a41b80c.zip |
lib: remove snprintf from prefix2str
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/prefix.c')
-rw-r--r-- | lib/prefix.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index 134d9cf90..7abeebcd0 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1329,13 +1329,29 @@ const char *prefix2str(union prefixconstptr pu, char *str, int size) { const struct prefix *p = pu.p; char buf[PREFIX2STR_BUFFER]; + int byte, tmp, a, b; + bool z = false; + size_t l; switch (p->family) { case AF_INET: case AF_INET6: - snprintf(str, size, "%s/%d", inet_ntop(p->family, &p->u.prefix, - buf, PREFIX2STR_BUFFER), - p->prefixlen); + inet_ntop(p->family, &p->u.prefix, buf, sizeof(buf)); + l = strlen(buf); + buf[l++] = '/'; + byte = p->prefixlen; + if ((tmp = p->prefixlen - 100) >= 0) { + buf[l++] = '1'; + z = true; + byte = tmp; + } + b = byte % 10; + a = byte / 10; + if (a || z) + buf[l++] = '0' + a; + buf[l++] = '0' + b; + buf[l] = '\0'; + strlcpy(str, buf, size); break; case AF_ETHERNET: @@ -1349,11 +1365,11 @@ const char *prefix2str(union prefixconstptr pu, char *str, int size) break; case AF_FLOWSPEC: - sprintf(str, "FS prefix"); + strlcpy(str, "FS prefix", size); break; default: - sprintf(str, "UNK prefix"); + strlcpy(str, "UNK prefix", size); break; } |