diff options
author | David Benjamin <davidben@google.com> | 2016-12-22 01:40:58 (GMT) |
---|---|---|
committer | David Benjamin <davidben@google.com> | 2016-12-22 01:57:21 (GMT) |
commit | 53c478d639b8eebd2942e88266610ebc79c541f6 (patch) | |
tree | 3ce5fee40e4ed41903208461598b25dfcd599da4 /googletest/src | |
parent | 5e7fd50e17b6edf1cadff973d0ec68966cf3265e (diff) | |
download | googletest-53c478d639b8eebd2942e88266610ebc79c541f6.zip googletest-53c478d639b8eebd2942e88266610ebc79c541f6.tar.gz googletest-53c478d639b8eebd2942e88266610ebc79c541f6.tar.bz2 |
Annotate ColoredPrintf with the format attribute and fix bugs.refs/pull/965/head
googletest doesn't currently build with clang's very aggressive
-Wformat-nonliteral warning. It requires that all non-literal format
strings come from the argument of a function annotated with a compatible
format attribute.
Fixing that reports that ColoredPrintf's callers weren't passing the
normal -Wformat warning. Some messages were passed directly into the
format string rather than via "%s".
Diffstat (limited to 'googletest/src')
-rw-r--r-- | googletest/src/gtest.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d882ab2..8ff3962 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2953,6 +2953,7 @@ bool ShouldUseColor(bool stdout_is_tty) { // cannot simply emit special characters and have the terminal change colors. // This routine must actually emit the characters rather than return a string // that would be colored when printed, as can be done on Linux. +GTEST_ATTRIBUTE_PRINTF_(2, 3) void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_list args; va_start(args, fmt); @@ -4729,7 +4730,7 @@ bool ShouldShard(const char* total_shards_env, << "Invalid environment variables: you have " << kTestShardIndex << " = " << shard_index << ", but have left " << kTestTotalShards << " unset.\n"; - ColoredPrintf(COLOR_RED, msg.GetString().c_str()); + ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); } else if (total_shards != -1 && shard_index == -1) { @@ -4737,7 +4738,7 @@ bool ShouldShard(const char* total_shards_env, << "Invalid environment variables: you have " << kTestTotalShards << " = " << total_shards << ", but have left " << kTestShardIndex << " unset.\n"; - ColoredPrintf(COLOR_RED, msg.GetString().c_str()); + ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); } else if (shard_index < 0 || shard_index >= total_shards) { @@ -4746,7 +4747,7 @@ bool ShouldShard(const char* total_shards_env, << kTestShardIndex << " < " << kTestTotalShards << ", but you have " << kTestShardIndex << "=" << shard_index << ", " << kTestTotalShards << "=" << total_shards << ".\n"; - ColoredPrintf(COLOR_RED, msg.GetString().c_str()); + ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); } |