- check for empty strings before using substr to avoid crashes with more strict C++ engine

This commit is contained in:
SoftCoder
2017-09-30 21:46:56 -07:00
parent a7a92056eb
commit edfb1508f5
6 changed files with 49 additions and 53 deletions

View File

@@ -301,15 +301,17 @@ Ip::Ip(unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned c
}
Ip::Ip(const string& ipString){
Ip::Ip(const string &ipString) {
size_t offset= 0;
int byteIndex= 0;
for(byteIndex= 0; byteIndex<4; ++byteIndex){
size_t dotPos= ipString.find_first_of('.', offset);
if(ipString.empty() == false) {
for(byteIndex= 0; byteIndex<4; ++byteIndex){
size_t dotPos= ipString.find_first_of('.', offset);
bytes[byteIndex]= atoi(ipString.substr(offset, dotPos-offset).c_str());
offset= dotPos+1;
bytes[byteIndex]= atoi(ipString.substr(offset, dotPos-offset).c_str());
offset= dotPos+1;
}
}
}