From 6ec5e8caa77829d7ea3593b08f1f91244d027601 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 25 Jan 2015 16:25:15 +0100 Subject: Replaced atoi() with StringToInteger(). --- src/Generating/BioGen.cpp | 3 +-- src/HTTPServer/HTTPMessage.cpp | 5 ++++- src/HTTPServer/HTTPServer.cpp | 4 ++-- src/RCONServer.cpp | 4 ++-- src/Server.cpp | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 2cc810d3b..378ece6a3 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -205,8 +205,7 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) int Count = 1; if (Split2.size() >= 2) { - Count = atol(Split2[1].c_str()); - if (Count <= 0) + if (!StringToInteger(Split2[1], Count)) { LOGWARNING("Cannot decode biome count: \"%s\"; using 1.", Split2[1].c_str()); Count = 1; diff --git a/src/HTTPServer/HTTPMessage.cpp b/src/HTTPServer/HTTPMessage.cpp index d59ca438e..c87b3cc8b 100644 --- a/src/HTTPServer/HTTPMessage.cpp +++ b/src/HTTPServer/HTTPMessage.cpp @@ -55,7 +55,10 @@ void cHTTPMessage::AddHeader(const AString & a_Key, const AString & a_Value) } else if (Key == "content-length") { - m_ContentLength = static_cast(atol(m_Headers[Key].c_str())); + if (!StringToInteger(m_Headers[Key], m_ContentLength)) + { + m_ContentLength = 0; + } } } diff --git a/src/HTTPServer/HTTPServer.cpp b/src/HTTPServer/HTTPServer.cpp index 3bcf0783a..71f974a97 100644 --- a/src/HTTPServer/HTTPServer.cpp +++ b/src/HTTPServer/HTTPServer.cpp @@ -225,8 +225,8 @@ bool cHTTPServer::Start(cCallbacks & a_Callbacks, const AStringVector & a_Ports) // Open up requested ports: for (auto port : a_Ports) { - UInt16 PortNum = static_cast(atoi(port.c_str())); - if (PortNum == 0) + UInt16 PortNum; + if (!StringToInteger(port, PortNum)) { LOGWARNING("WebServer: Invalid port value: \"%s\". Ignoring.", port.c_str()); continue; diff --git a/src/RCONServer.cpp b/src/RCONServer.cpp index 63bc97fe3..cd8409367 100644 --- a/src/RCONServer.cpp +++ b/src/RCONServer.cpp @@ -155,8 +155,8 @@ void cRCONServer::Initialize(cIniFile & a_IniFile) // Start listening on each specified port: for (auto port: Ports) { - UInt16 PortNum = static_cast(atol(port.c_str())); - if (PortNum == 0) + UInt16 PortNum; + if (!StringToInteger(port, PortNum)) { LOGINFO("Invalid RCON port value: \"%s\". Ignoring.", port.c_str()); continue; diff --git a/src/Server.cpp b/src/Server.cpp index 783b12947..3f61be378 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -393,8 +393,8 @@ bool cServer::Start(void) { for (auto port: m_Ports) { - UInt16 PortNum = static_cast(atoi(port.c_str())); - if (PortNum == 0) + UInt16 PortNum; + if (!StringToInteger(port, PortNum)) { LOGWARNING("Invalid port specified for server: \"%s\". Ignoring.", port.c_str()); continue; -- cgit v1.2.3