Fix Coverity warnings
This commit is contained in:
parent
0eac037416
commit
c4d0bc1ac9
@ -34,6 +34,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
@ -247,11 +248,11 @@ TEST(FileTest, OpenRetry) {
|
|||||||
TEST(FileTest, CloseNoRetryInDtor) {
|
TEST(FileTest, CloseNoRetryInDtor) {
|
||||||
File read_end, write_end;
|
File read_end, write_end;
|
||||||
File::pipe(read_end, write_end);
|
File::pipe(read_end, write_end);
|
||||||
File *f = new File(std::move(read_end));
|
std::auto_ptr<File> f(new File(std::move(read_end)));
|
||||||
int saved_close_count = 0;
|
int saved_close_count = 0;
|
||||||
EXPECT_WRITE(stderr, {
|
EXPECT_WRITE(stderr, {
|
||||||
close_count = 1;
|
close_count = 1;
|
||||||
delete f;
|
f.reset();
|
||||||
saved_close_count = close_count;
|
saved_close_count = close_count;
|
||||||
close_count = 0;
|
close_count = 0;
|
||||||
}, format_system_error(EINTR, "cannot close file") + "\n");
|
}, format_system_error(EINTR, "cannot close file") + "\n");
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "gtest-extra.h"
|
#include "gtest-extra.h"
|
||||||
#include "posix.h"
|
#include "posix.h"
|
||||||
@ -136,14 +137,14 @@ TEST(BufferedFileTest, CloseFileInDtor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferedFileTest, CloseErrorInDtor) {
|
TEST(BufferedFileTest, CloseErrorInDtor) {
|
||||||
BufferedFile *f = new BufferedFile(open_buffered_file());
|
std::auto_ptr<BufferedFile> f(new BufferedFile(open_buffered_file()));
|
||||||
EXPECT_WRITE(stderr, {
|
EXPECT_WRITE(stderr, {
|
||||||
// The close function must be called inside EXPECT_WRITE, otherwise
|
// The close function must be called inside EXPECT_WRITE, otherwise
|
||||||
// the system may recycle closed file descriptor when redirecting the
|
// the system may recycle closed file descriptor when redirecting the
|
||||||
// output in EXPECT_STDERR and the second close will break output
|
// output in EXPECT_STDERR and the second close will break output
|
||||||
// redirection.
|
// redirection.
|
||||||
FMT_POSIX(close(f->fileno()));
|
FMT_POSIX(close(f->fileno()));
|
||||||
SUPPRESS_ASSERT(delete f);
|
SUPPRESS_ASSERT(f.reset());
|
||||||
}, format_system_error(EBADF, "cannot close file") + "\n");
|
}, format_system_error(EBADF, "cannot close file") + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user