Fix tautological unsigned comparison (#28537)

* Fix invalid unsigned comparison

This also enables the -Wtype-limits warning, which is included in GCC's
-Wextra, but not in Clang's -Wextra.
pull/28552/head
AJ Heller 3 years ago committed by GitHub
parent b64167a034
commit e22f07dc4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      bazel/copts.bzl
  2. 14
      src/core/ext/filters/fault_injection/service_config_parser.cc

@ -47,6 +47,8 @@ GRPC_LLVM_WARNING_FLAGS = [
"-Wthread-safety-beta",
"-Wunused-comparison",
"-Wvla",
# -Wextra compatibility between gcc and clang
"-Wtype-limits",
# A list of disabled flags coming from internal build system
"-Wno-string-concatenation",
# Exceptions but will be removed

@ -122,14 +122,12 @@ ParseFaultInjectionPolicy(const Json::Array& policies_json_array,
}
}
// Parse max_faults
if (ParseJsonObjectField(json_object, "maxFaults",
&fault_injection_policy.max_faults,
&sub_error_list, false)) {
if (fault_injection_policy.max_faults < 0) {
sub_error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"field:maxFaults error:should be zero or positive"));
}
}
static_assert(
std::is_unsigned<decltype(fault_injection_policy.max_faults)>::value,
"maxFaults should be unsigned");
ParseJsonObjectField(json_object, "maxFaults",
&fault_injection_policy.max_faults, &sub_error_list,
false);
if (!sub_error_list.empty()) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING(
absl::StrCat("failed to parse faultInjectionPolicy index ", i),

Loading…
Cancel
Save