- 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

@@ -270,23 +270,6 @@ int64 Chrono::getCurTicks() {
// =====================================
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters) {
/*
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos) {
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
*/
// Assume textLine contains the line of text to parse.
string textLine = str;

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;
}
}
}