fix #5: segfault when program not exist

This commit is contained in:
Fancy Zhang
2020-06-27 10:06:04 +08:00
parent 46fb9bae2b
commit 4618b8f475
2 changed files with 3 additions and 3 deletions

View File

@@ -67,7 +67,7 @@ string bash_which(const string &name) {
char buf[READ_SIZE_MAX];
while (fgets(buf, READ_SIZE_MAX, fp.get()) != NULL) { buffer << buf; }
string s = buffer.str();
s.pop_back(); // remove newline character
if (!s.empty()) s.pop_back(); // remove newline character
return s;
}
@@ -79,7 +79,7 @@ string bash_readlink(const string &path) {
char buf[READ_SIZE_MAX];
while (fgets(buf, READ_SIZE_MAX, fp.get()) != NULL) { buffer << buf; }
string s = buffer.str();
s.pop_back(); // remove newline character
if (!s.empty()) s.pop_back(); // remove newline character
return s;
}