From d44d76cf58b74122eed3524cdd8227866b694f5d Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Sun, 23 May 2010 17:04:05 -0600 Subject: [PATCH] Fixed IpAddress port printing for ports higher than 9999: snprintf includes zero-terminator in its size limit, so 7 rather than 6 bytes are needed to snprintf a colon followed by 5 port digits. --- src/ip/Address.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ip/Address.cc b/src/ip/Address.cc index 6ed6234842..69e406e236 100644 --- a/src/ip/Address.cc +++ b/src/ip/Address.cc @@ -1061,9 +1061,9 @@ Ip::Address::ToURL(char* buf, unsigned int blen) const p += ToHostname(p, blen); - if (m_SocketAddr.sin6_port > 0 && p < (buf+blen-6) ) { - /* 6 is max length of expected ':port' (short int) */ - snprintf(p, 6,":%d", GetPort() ); + if (m_SocketAddr.sin6_port > 0 && p <= (buf+blen-7) ) { + // ':port' (short int) needs at most 6 bytes plus 1 for 0-terminator + snprintf(p, 7, ":%d", GetPort() ); } // force a null-terminated string -- 2.47.3