]> git.saurik.com Git - wxWidgets.git/commitdiff
Make variable containing port number an ushort in the sockets sample.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 16 May 2012 15:10:05 +0000 (15:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 16 May 2012 15:10:05 +0000 (15:10 +0000)
A port number is an unsigned short, not long, so don't make it long just
because wxCmdLineParser doesn't provide a convenient way to get the value of
an unsigned short option (it would be nice if it did...).

This fixes the problem with using "%d" format specifier with a long variable
as this resulted in an assert under LP64 systems.

See #14311.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71443 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/sockets/baseserver.cpp

index ac856e80a269c0d18c85d191665f715550f9e744..f00d05a2ed9813fcdc932d1a0b152659a1eab8a8 100644 (file)
@@ -142,7 +142,7 @@ private:
 
     long int m_maxConnections;
 
-    long m_port;
+    unsigned short m_port;
 
     wxTimer mTimer;
 };
@@ -282,9 +282,18 @@ Server::OnCmdLineParsed(wxCmdLineParser& pParser)
         wxLogMessage("%d connection(s) to exit",m_maxConnections);
     }
 
-    if (pParser.Found("p",&m_port))
+    long port;
+    if (pParser.Found("p", &port))
     {
-        wxLogMessage("%d connection(s) to exit",m_maxConnections);
+        if ( port <= 0 || port > USHRT_MAX )
+        {
+            wxLogError("Invalid port number %ld, must be in 0..%u range.",
+                       port, USHRT_MAX);
+            return false;
+        }
+
+        m_port = static_cast<unsigned short>(port);
+        wxLogMessage("Will listen on port %u", m_port);
     }
 
     if (pParser.Found("t"))
@@ -331,7 +340,7 @@ bool Server::OnInit()
     m_eventWorkersFailed = 0;
     m_maxEventWorkers = 0;
 
-    wxLogMessage("Server listening at port %d, waiting for connections", m_port);
+    wxLogMessage("Server listening at port %u, waiting for connections", m_port);
     return true;
 }