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", "-Wthread-safety-beta",
"-Wunused-comparison", "-Wunused-comparison",
"-Wvla", "-Wvla",
# -Wextra compatibility between gcc and clang
"-Wtype-limits",
# A list of disabled flags coming from internal build system # A list of disabled flags coming from internal build system
"-Wno-string-concatenation", "-Wno-string-concatenation",
# Exceptions but will be removed # Exceptions but will be removed

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

Loading…
Cancel
Save