From 2d727e7d0eb521352c1269f57b8fa837c00df827 Mon Sep 17 00:00:00 2001 From: vitaut Date: Wed, 28 Oct 2015 07:01:28 -0700 Subject: [PATCH] Suppress bogus coverity warnings --- format.cc | 7 ++++--- format.h | 3 ++- test/gtest-extra-test.cc | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/format.cc b/format.cc index abc5354e..a9577028 100644 --- a/format.cc +++ b/format.cc @@ -444,19 +444,20 @@ class BasicArgFormatter : public ArgVisitor { typedef typename BasicWriter::CharPtr CharPtr; Char fill = internal::CharTraits::cast(spec_.fill()); CharPtr out = CharPtr(); - enum { CHAR_WIDTH = 1 }; + const int CHAR_WIDTH = 1; if (spec_.width_ > CHAR_WIDTH) { out = writer_.grow_buffer(spec_.width_); if (spec_.align_ == ALIGN_RIGHT) { std::fill_n(out, spec_.width_ - CHAR_WIDTH, fill); out += spec_.width_ - CHAR_WIDTH; } else if (spec_.align_ == ALIGN_CENTER) { - out = writer_.fill_padding(out, spec_.width_, CHAR_WIDTH, fill); + out = writer_.fill_padding(out, spec_.width_, + internal::check(CHAR_WIDTH), fill); } else { std::fill_n(out + CHAR_WIDTH, spec_.width_ - CHAR_WIDTH, fill); } } else { - out = writer_.grow_buffer(1); + out = writer_.grow_buffer(CHAR_WIDTH); } *out = internal::CharTraits::cast(value); } diff --git a/format.h b/format.h index aea41bfb..68c7e51b 100644 --- a/format.h +++ b/format.h @@ -921,7 +921,8 @@ struct Conditional { typedef F type; }; // A helper function to suppress bogus "conditional expression is constant" // warnings. -inline bool check(bool value) { return value; } +template +inline T check(T value) { return value; } // Makes an Arg object from any type. template diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index 93a1eca3..d1c3ccdf 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -42,6 +42,7 @@ using testing::internal::scoped_ptr; namespace { +// 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) @@ -385,7 +386,7 @@ TEST(OutputRedirectTest, RestoreAndRead) { OutputRedirect redir(file.get()); std::fprintf(file.get(), "censored"); EXPECT_EQ("censored", sanitize(redir.restore_and_read())); - EXPECT_EQ("", redir.restore_and_read()); + EXPECT_EQ("", sanitize(redir.restore_and_read())); std::fprintf(file.get(), "]]]"); file = BufferedFile(); EXPECT_READ(read_end, "[[[]]]");