Merge pull request #76 from slsdetectorgroup/exec

Buffern in exec
This commit is contained in:
Dhanya Thattil 2020-02-04 10:59:48 +01:00 committed by GitHub
commit 94fcf52e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -206,23 +206,19 @@ bool DetectorImpl::isAcquireReady() {
}
std::string DetectorImpl::exec(const char *cmd) {
int bufsize = 128;
char buffer[bufsize];
std::string result = "";
char buffer[128];
std::string result;
FILE *pipe = popen(cmd, "r");
if (pipe == nullptr) {
throw RuntimeError("Could not open pipe");
}
try {
while (feof(pipe) == 0) {
if (fgets(buffer, bufsize, pipe) != nullptr) {
result += buffer;
}
while (feof(pipe) == 0) {
if (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
result += buffer;
}
} catch (...) {
pclose(pipe);
throw;
}
pclose(pipe);
result.erase(result.find_last_not_of(" \t\n\r") + 1);
return result;