[Lldb-commits] [lldb] r259638 - Fix an off-by-one in SocketTest::DecodeHostAndPort

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 3 03:12:23 PST 2016


Author: labath
Date: Wed Feb  3 05:12:23 2016
New Revision: 259638

URL: http://llvm.org/viewvc/llvm-project?rev=259638&view=rev
Log:
Fix an off-by-one in SocketTest::DecodeHostAndPort

65535 is still a valid port. This should fix the android failures we were getting when we chose
to connect over 65535 to the remote lldb-server.

Modified:
    lldb/trunk/source/Host/common/Socket.cpp
    lldb/trunk/unittests/Host/SocketTest.cpp

Modified: lldb/trunk/source/Host/common/Socket.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Socket.cpp?rev=259638&r1=259637&r2=259638&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Socket.cpp (original)
+++ lldb/trunk/source/Host/common/Socket.cpp Wed Feb  3 05:12:23 2016
@@ -268,7 +268,7 @@ Socket::DecodeHostAndPort(llvm::StringRe
         {
             bool ok = false;
             port = StringConvert::ToUInt32 (port_str.c_str(), UINT32_MAX, 10, &ok);
-            if (ok && port < UINT16_MAX)
+            if (ok && port <= UINT16_MAX)
             {
                 if (error_ptr)
                     error_ptr->Clear();

Modified: lldb/trunk/unittests/Host/SocketTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/SocketTest.cpp?rev=259638&r1=259637&r2=259638&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/SocketTest.cpp (original)
+++ lldb/trunk/unittests/Host/SocketTest.cpp Wed Feb  3 05:12:23 2016
@@ -116,7 +116,11 @@ TEST_F (SocketTest, DecodeHostAndPort)
     EXPECT_FALSE (Socket::DecodeHostAndPort ("google.com:-1138", host_str, port_str, port, &error));
     EXPECT_TRUE (error.Fail ());
     EXPECT_STREQ ("invalid host:port specification: 'google.com:-1138'", error.AsCString ());
-    
+
+    EXPECT_FALSE(Socket::DecodeHostAndPort("google.com:65536", host_str, port_str, port, &error));
+    EXPECT_TRUE(error.Fail());
+    EXPECT_STREQ("invalid host:port specification: 'google.com:65536'", error.AsCString());
+
     EXPECT_TRUE (Socket::DecodeHostAndPort ("12345", host_str, port_str, port, &error));
     EXPECT_STREQ ("", host_str.c_str ());
     EXPECT_STREQ ("12345", port_str.c_str ());
@@ -128,6 +132,12 @@ TEST_F (SocketTest, DecodeHostAndPort)
     EXPECT_STREQ ("0", port_str.c_str ());
     EXPECT_EQ (0, port);
     EXPECT_TRUE (error.Success ());
+
+    EXPECT_TRUE(Socket::DecodeHostAndPort("*:65535", host_str, port_str, port, &error));
+    EXPECT_STREQ("*", host_str.c_str());
+    EXPECT_STREQ("65535", port_str.c_str());
+    EXPECT_EQ(65535, port);
+    EXPECT_TRUE(error.Success());
 }
 
 #ifndef LLDB_DISABLE_POSIX




More information about the lldb-commits mailing list