Files
c-toxcore/toxcore/network_test.cc
iphydf fd91bbdd7b test: Add a simple test for ip_ntoa.
Just to demonstrate that it will never exceed its input buffer.
2021-12-09 20:51:15 +00:00

21 lines
418 B
C++

#include "network.h"
#include <gtest/gtest.h>
namespace {
TEST(IpNtoa, DoesntWriteOutOfBounds) {
char ip_str[IP_NTOA_LEN];
IP ip;
ip.family = net_family_ipv6;
ip.ip.v6.uint64[0] = -1;
ip.ip.v6.uint64[1] = -1;
ip_ntoa(&ip, ip_str, sizeof(ip_str));
EXPECT_EQ(std::string(ip_str), "[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]");
EXPECT_LT(std::string(ip_str).length(), IP_NTOA_LEN);
}
} // namespace