Skip to content

Commit

Permalink
fix the issues scanned by Coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
xianju6x committed Feb 15, 2023
1 parent 7dd1b49 commit b7be35b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/guest/config_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ bool CivConfig::SanitizeOpts(void) {
if (group != kConfigMap.end()) {
for (auto& subsec : section.second) {
auto key = std::find(group->second.begin(), group->second.end(), subsec.first);
if (key != group->second.end()) {
continue;
} else {
if (key == group->second.end()) {
LOG(error) << "Invalid key: " << section.first << "." << subsec.first << "\n";
return false;
}
Expand Down
7 changes: 3 additions & 4 deletions src/guest/vm_flash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,14 @@ bool VmFlasher::FlashGuest(std::string path) {

if (!cfg_.ReadConfigFile(p.string())) {
LOG(error) << "Failed to read config file";
return -1;
return false;
}

std::string emul_type = cfg_.GetValue(kGroupEmul, kEmulType);
if (emul_type.compare(kEmulTypeQemu) == 0) {
return FlashWithQemu();
} else {
if ((emul_type.compare(kEmulTypeQemu) == 0) || emul_type.empty()) {
return FlashWithQemu();
}
return false;
}

} // namespace vm_manager
6 changes: 4 additions & 2 deletions src/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const char *GetConfigPath(void) {
}

if (sudo_uid) {
euid = atoi(sudo_gid);
euid = atoi(sudo_uid);
setresuid(ruid, euid, suid);
}

Expand Down Expand Up @@ -106,8 +106,10 @@ int Daemonize(void) {
close(STDERR_FILENO);

int fd = open("/dev/null", O_RDWR);
if (fd != STDIN_FILENO)
if (fd != STDIN_FILENO) {
close(fd);
return -1;
}
if (dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO)
return -1;
if (dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO)
Expand Down

0 comments on commit b7be35b

Please sign in to comment.