diff --git a/src/cgroup_attach.cpp b/src/cgroup_attach.cpp index 4eb5a79..0ce0cf2 100644 --- a/src/cgroup_attach.cpp +++ b/src/cgroup_attach.cpp @@ -24,7 +24,7 @@ string get_cgroup2_mount_point() { 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; } diff --git a/src/common.cpp b/src/common.cpp index 18dd4bb..8871064 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -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; }