Should fix: "fd" is passed to a parameter that cannot be negative.
CID
1019566 Improper use of negative value (NEGATIVE_RETURNS, CWE-394)
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
int fd;
if (vm.count("out")) {
- fd = open(out_path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ if ((fd = open(out_path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
+ int _err = errno;
+ std::cerr << "Couldn't open " << out_path << cpp_strerror(_err) << std::endl;
+ return 1;
+ }
} else {
fd = STDOUT_FILENO;
}