forked from fmtlib/fmt
Suppress bogus coverity warnings
This commit is contained in:
@@ -444,19 +444,20 @@ class BasicArgFormatter : public ArgVisitor<Impl, void> {
|
|||||||
typedef typename BasicWriter<Char>::CharPtr CharPtr;
|
typedef typename BasicWriter<Char>::CharPtr CharPtr;
|
||||||
Char fill = internal::CharTraits<Char>::cast(spec_.fill());
|
Char fill = internal::CharTraits<Char>::cast(spec_.fill());
|
||||||
CharPtr out = CharPtr();
|
CharPtr out = CharPtr();
|
||||||
enum { CHAR_WIDTH = 1 };
|
const int CHAR_WIDTH = 1;
|
||||||
if (spec_.width_ > CHAR_WIDTH) {
|
if (spec_.width_ > CHAR_WIDTH) {
|
||||||
out = writer_.grow_buffer(spec_.width_);
|
out = writer_.grow_buffer(spec_.width_);
|
||||||
if (spec_.align_ == ALIGN_RIGHT) {
|
if (spec_.align_ == ALIGN_RIGHT) {
|
||||||
std::fill_n(out, spec_.width_ - CHAR_WIDTH, fill);
|
std::fill_n(out, spec_.width_ - CHAR_WIDTH, fill);
|
||||||
out += spec_.width_ - CHAR_WIDTH;
|
out += spec_.width_ - CHAR_WIDTH;
|
||||||
} else if (spec_.align_ == ALIGN_CENTER) {
|
} 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 {
|
} else {
|
||||||
std::fill_n(out + CHAR_WIDTH, spec_.width_ - CHAR_WIDTH, fill);
|
std::fill_n(out + CHAR_WIDTH, spec_.width_ - CHAR_WIDTH, fill);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out = writer_.grow_buffer(1);
|
out = writer_.grow_buffer(CHAR_WIDTH);
|
||||||
}
|
}
|
||||||
*out = internal::CharTraits<Char>::cast(value);
|
*out = internal::CharTraits<Char>::cast(value);
|
||||||
}
|
}
|
||||||
|
3
format.h
3
format.h
@@ -921,7 +921,8 @@ struct Conditional<false, T, F> { typedef F type; };
|
|||||||
|
|
||||||
// A helper function to suppress bogus "conditional expression is constant"
|
// A helper function to suppress bogus "conditional expression is constant"
|
||||||
// warnings.
|
// warnings.
|
||||||
inline bool check(bool value) { return value; }
|
template <typename T>
|
||||||
|
inline T check(T value) { return value; }
|
||||||
|
|
||||||
// Makes an Arg object from any type.
|
// Makes an Arg object from any type.
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
|
@@ -42,6 +42,7 @@ using testing::internal::scoped_ptr;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// This is used to suppress coverity warnings about untrusted values.
|
||||||
std::string sanitize(const std::string &s) {
|
std::string sanitize(const std::string &s) {
|
||||||
std::string result;
|
std::string result;
|
||||||
for (std::string::const_iterator i = s.begin(), end = s.end(); i != end; ++i)
|
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());
|
OutputRedirect redir(file.get());
|
||||||
std::fprintf(file.get(), "censored");
|
std::fprintf(file.get(), "censored");
|
||||||
EXPECT_EQ("censored", sanitize(redir.restore_and_read()));
|
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(), "]]]");
|
std::fprintf(file.get(), "]]]");
|
||||||
file = BufferedFile();
|
file = BufferedFile();
|
||||||
EXPECT_READ(read_end, "[[[]]]");
|
EXPECT_READ(read_end, "[[[]]]");
|
||||||
|
Reference in New Issue
Block a user