Fix build with GCC 4.9.2 and -Wtype-limits.
gRPC builds on Debian Jessie, which has GCC 4.9.2, and builds with
-Wtype-limits, which makes it warn about code intended for 64-bit
systems when building on 32-bit systems.
We have tried to avoid these issues with Clang previously by guarding
with “sizeof(size_t) > 4”, but this version of GCC isn't smart enough to
figure that out.
Change-Id: I800ceb3891436fa7c81474ede4b8656021568357
Reviewed-on: https://boringssl-review.googlesource.com/28247
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/ssl/d1_both.cc b/ssl/d1_both.cc
index d29af78..31c83c6 100644
--- a/ssl/d1_both.cc
+++ b/ssl/d1_both.cc
@@ -536,6 +536,20 @@
return true;
}
+// ssl_size_t_greater_than_32_bits returns whether |v| exceeds the bounds of a
+// 32-bit value. The obvious thing doesn't work because, in some 32-bit build
+// configurations, the compiler warns that the test is always false and breaks
+// the build.
+static bool ssl_size_t_greater_than_32_bits(size_t v) {
+#if defined(OPENSSL_64_BIT)
+ return v > 0xffffffff;
+#elif defined(OPENSSL_32_BIT)
+ return false;
+#else
+#error "Building for neither 32- nor 64-bits."
+#endif
+}
+
// add_outgoing adds a new handshake message or ChangeCipherSpec to the current
// outgoing flight. It returns true on success and false on error.
static bool add_outgoing(SSL *ssl, bool is_ccs, Array<uint8_t> data) {
@@ -550,7 +564,7 @@
(1 << 8 * sizeof(ssl->d1->outgoing_messages_len)),
"outgoing_messages_len is too small");
if (ssl->d1->outgoing_messages_len >= SSL_MAX_HANDSHAKE_FLIGHT ||
- static_cast<uint64_t>(data.size()) > 0xffffffff) {
+ ssl_size_t_greater_than_32_bits(data.size())) {
assert(false);
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
return false;