forked from Mirror/frr
lib: remove snprintf from prefix2str
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
6a81b60a94
commit
ec466f6546
26
lib/prefix.c
26
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ check_PROGRAMS = \
|
|||
tests/lib/test_memory \
|
||||
tests/lib/test_nexthop_iter \
|
||||
tests/lib/test_ntop \
|
||||
tests/lib/test_prefix2str \
|
||||
tests/lib/test_printfrr \
|
||||
tests/lib/test_privs \
|
||||
tests/lib/test_ringbuf \
|
||||
|
@ -236,6 +237,10 @@ tests_lib_test_ntop_CFLAGS = $(TESTS_CFLAGS)
|
|||
tests_lib_test_ntop_CPPFLAGS = $(TESTS_CPPFLAGS)
|
||||
tests_lib_test_ntop_LDADD = # none
|
||||
tests_lib_test_ntop_SOURCES = tests/lib/test_ntop.c tests/helpers/c/prng.c
|
||||
tests_lib_test_prefix2str_CFLAGS = $(TESTS_CFLAGS)
|
||||
tests_lib_test_prefix2str_CPPFLAGS = $(TESTS_CPPFLAGS)
|
||||
tests_lib_test_prefix2str_LDADD = $(ALL_TESTS_LDADD)
|
||||
tests_lib_test_prefix2str_SOURCES = tests/lib/test_prefix2str.c tests/helpers/c/prng.c
|
||||
tests_lib_test_printfrr_CFLAGS = $(TESTS_CFLAGS)
|
||||
tests_lib_test_printfrr_CPPFLAGS = $(TESTS_CPPFLAGS)
|
||||
tests_lib_test_printfrr_LDADD = $(ALL_TESTS_LDADD)
|
||||
|
@ -328,6 +333,7 @@ EXTRA_DIST += \
|
|||
tests/lib/test_atomlist.py \
|
||||
tests/lib/test_nexthop_iter.py \
|
||||
tests/lib/test_ntop.py \
|
||||
tests/lib/test_prefix2str.py \
|
||||
tests/lib/test_printfrr.py \
|
||||
tests/lib/test_ringbuf.py \
|
||||
tests/lib/test_srcdest_table.py \
|
||||
|
|
Loading…
Reference in a new issue