From 0945afa159d0da327d4da8d2c4e7d345d308cd97 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 2 Jul 2021 13:56:21 -0400 Subject: Avoid allegedly "suspicious" string comparisons I guess these are suspicious if you've never seen C before? --- .clang-tidy | 1 - benchmark/.clang-tidy | 1 - benchmark/dict_bench.c | 4 ++-- src/strindex.c | 2 +- test/.clang-tidy | 1 - test/strindex_test.c | 2 +- 6 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 817a439..fc5d670 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,7 +3,6 @@ Checks: > -*-magic-numbers, -*-uppercase-literal-suffix, -bugprone-reserved-identifier, - -bugprone-suspicious-string-compare, -cert-dcl37-c, -cert-dcl51-cpp, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, diff --git a/benchmark/.clang-tidy b/benchmark/.clang-tidy index 2c16e13..038fecc 100644 --- a/benchmark/.clang-tidy +++ b/benchmark/.clang-tidy @@ -4,7 +4,6 @@ Checks: > -*-uppercase-literal-suffix, -android-cloexec-fopen, -bugprone-reserved-identifier, - -bugprone-suspicious-string-compare, -cert-dcl37-c, -cert-dcl51-cpp, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, diff --git a/benchmark/dict_bench.c b/benchmark/dict_bench.c index 4a77257..90b0abc 100644 --- a/benchmark/dict_bench.c +++ b/benchmark/dict_bench.c @@ -165,7 +165,7 @@ main(int argc, char** argv) for (size_t i = 0; i < n; ++i) { const size_t index = lcg64(seed + i) % n; char* match = (char*)g_hash_table_lookup(hash, strings[index]); - if (strcmp(match, strings[index])) { + if (!!strcmp(match, strings[index])) { return test_fail("Bad match for `%s'\n", strings[index]); } } @@ -181,7 +181,7 @@ main(int argc, char** argv) return test_fail("Hash: Failed to find `%s'\n", strings[index]); } - if (strcmp((const char*)match->buf, strings[index])) { + if (!!strcmp((const char*)match->buf, strings[index])) { return test_fail("Hash: Bad match %p for `%s': `%s'\n", (const void*)match, strings[index], diff --git a/src/strindex.c b/src/strindex.c index 9a6d952..f800210 100644 --- a/src/strindex.c +++ b/src/strindex.c @@ -226,7 +226,7 @@ zix_strindex_find(ZixStrindex* strindex, const char* const str, char** match) assert((*match)[0] == orig_p[0]); } - if (strncmp(p, label_first, max_len)) { + if (!!strncmp(p, label_first, max_len)) { /* no match */ *match = NULL; return ZIX_STATUS_NOT_FOUND; diff --git a/test/.clang-tidy b/test/.clang-tidy index 036a68c..4d7a003 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -5,7 +5,6 @@ Checks: > -android-cloexec-fopen, -bugprone-reserved-identifier, -bugprone-suspicious-include, - -bugprone-suspicious-string-compare, -cert-dcl37-c, -cert-dcl51-cpp, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, diff --git a/test/strindex_test.c b/test/strindex_test.c index 3cdfb25..bd6a389 100644 --- a/test/strindex_test.c +++ b/test/strindex_test.c @@ -52,7 +52,7 @@ main(void) "No match for substring at %" PRIuPTR " length %" PRIuPTR "\n", i, l); } - if (strncmp(str + i, match, l)) { + if (!!strncmp(str + i, match, l)) { return test_fail("Bad match for substring at %" PRIuPTR " length %" PRIuPTR "\n", i, -- cgit v1.2.1