1. Ignore errors from fsetpos to mute complaint from Coverity
2. Make sure the first dup2 succeeds to quell complaints from Coverity
about negative values being passed into the subsequent dup2 call.
3. Unconditionally close fd [3]. Although it's unlikely for freopen to
fail, it can happen.. closing fd shouldn't be contingent on freopen's
success.
CID:
1364318 [1],
1364322 [2],
1365233 [3]
/* bunzip2 will write to stderr, redirect it to a file */
fflush(stderr);
fgetpos(stderr, &pos);
- fd = dup(fileno(stderr));
- fp = freopen("stderr1", "w", stderr);
+ assert((fd = dup(fileno(stderr))) != -1);
+ fp = freopen("stderr1", "w", stderr);
#endif
assert((a = archive_read_new()) != NULL);
if (fp != NULL) {
fflush(stderr);
dup2(fd, fileno(stderr));
- close(fd);
clearerr(stderr);
- fsetpos(stderr, &pos);
+ (void)fsetpos(stderr, &pos);
}
+ close(fd);
assertTextFileContents("bunzip2: (stdin) is not a bzip2 file.\n", "stderr1");
#endif
}