From a40e79ffddcaed12ec62c1dabae51faf5c5530af Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 27 Dec 2021 23:07:45 +0100 Subject: [PATCH] Fix crash on empty string --- HostFile.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/HostFile.cpp b/HostFile.cpp index 0c88ff7..f7b276d 100644 --- a/HostFile.cpp +++ b/HostFile.cpp @@ -49,17 +49,16 @@ m_locks() char * lineDup = strdup(line.c_str()); char * t = std::strtok(lineDup, delimiters.c_str()); - std::string name(t); + std::string name(t != NULL ? t : ""); t = std::strtok(NULL, delimiters.c_str()); - std::string address(t); + std::string address(t != NULL ? t : ""); t = std::strtok(NULL, delimiters.c_str()); - std::string lock(t); + std::string lock(t != NULL ? t : ""); free(lineDup); - name.resize(LONG_CALLSIGN_LENGTH, ' '); - if (!name.empty() && !address.empty()) { + name.resize(LONG_CALLSIGN_LENGTH, ' '); m_names.push_back(name); m_addresses.push_back(address); m_locks.push_back(!lock.empty());