From fb84dfc1881613ebb960e4e02d95ac8a21f89eb8 Mon Sep 17 00:00:00 2001 From: Ashton Fagg Date: Fri, 6 Nov 2020 17:19:12 -0500 Subject: [PATCH 1/4] Make OpenBSD not use fcntl --- include/fmt/os.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/os.h b/include/fmt/os.h index 7e181c86fc55..eb218cf5878d 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -31,7 +31,8 @@ #endif #if (FMT_HAS_INCLUDE() || defined(__APPLE__) || \ defined(__linux__)) && \ - (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) + (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) && \ + (!defined(__OpenBSD__)) # include // for O_RDONLY # define FMT_USE_FCNTL 1 #else From 61e57b32a07a3f2d8ed76cf0741c112200620a62 Mon Sep 17 00:00:00 2001 From: Ashton Fagg Date: Fri, 6 Nov 2020 17:27:03 -0500 Subject: [PATCH 2/4] Fix tests so they compile with -Werror and -pedantic when on a machine that's not using FCNTL --- test/gtest-extra-test.cc | 2 ++ test/posix-mock-test.cc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index ea728607e8d1..80777d9bafe3 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -22,6 +22,7 @@ namespace { +#if FMT_USE_FCNTL // This is used to suppress coverity warnings about untrusted values. std::string sanitize(const std::string& s) { std::string result; @@ -29,6 +30,7 @@ std::string sanitize(const std::string& s) { result.push_back(static_cast(*i & 0xff)); return result; } +#endif // Tests that assertion macros evaluate their arguments exactly once. class SingleEvaluationTest : public ::testing::Test { diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index eb85756d2d66..2f30e81c7ee6 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -194,12 +194,12 @@ int(test::fileno)(FILE* stream) { # define EXPECT_EQ_POSIX(expected, actual) #endif +#if FMT_USE_FCNTL static void write_file(fmt::cstring_view filename, fmt::string_view content) { fmt::buffered_file f(filename, "w"); f.print("{}", content); } -#if FMT_USE_FCNTL using fmt::file; TEST(UtilTest, GetPageSize) { From 68ed04e7a1512b03e8b046819352ac2f18001164 Mon Sep 17 00:00:00 2001 From: Ashton Fagg Date: Fri, 6 Nov 2020 17:37:45 -0500 Subject: [PATCH 3/4] Fix --- include/fmt/os.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/fmt/os.h b/include/fmt/os.h index eb218cf5878d..7e181c86fc55 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -31,8 +31,7 @@ #endif #if (FMT_HAS_INCLUDE() || defined(__APPLE__) || \ defined(__linux__)) && \ - (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) && \ - (!defined(__OpenBSD__)) + (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) # include // for O_RDONLY # define FMT_USE_FCNTL 1 #else From 7d6ae00c0897cd513c9b2755c7817c36e65f3cb0 Mon Sep 17 00:00:00 2001 From: Ashton Fagg Date: Fri, 6 Nov 2020 17:56:39 -0500 Subject: [PATCH 4/4] Sanitize() is apparently no longer needed - remove it --- test/gtest-extra-test.cc | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index 80777d9bafe3..8855bd357e16 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -22,16 +22,6 @@ namespace { -#if FMT_USE_FCNTL -// This is used to suppress coverity warnings about untrusted values. -std::string sanitize(const std::string& s) { - std::string result; - for (std::string::const_iterator i = s.begin(), end = s.end(); i != end; ++i) - result.push_back(static_cast(*i & 0xff)); - return result; -} -#endif - // Tests that assertion macros evaluate their arguments exactly once. class SingleEvaluationTest : public ::testing::Test { protected: @@ -390,8 +380,8 @@ TEST(OutputRedirectTest, RestoreAndRead) { std::fprintf(file.get(), "[[["); OutputRedirect redir(file.get()); std::fprintf(file.get(), "censored"); - EXPECT_EQ("censored", sanitize(redir.restore_and_read())); - EXPECT_EQ("", sanitize(redir.restore_and_read())); + EXPECT_EQ("censored", redir.restore_and_read()); + EXPECT_EQ("", redir.restore_and_read()); std::fprintf(file.get(), "]]]"); file = buffered_file(); EXPECT_READ(read_end, "[[[]]]");