From ef4962f5a38fd68f0b89b67fc5e13da70e4288f6 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Mon, 6 Apr 2015 20:31:44 -0400 Subject: [PATCH] Shush warning in alignment code. MSVC doesn't like unary - on unsigned numbers. Also switch ssl3_read_n's version to uintptr_t to match the write half. This gets us closer to clearing through C4311 violations. (The remaining one is in asn1_add_error which can go after verifying that most of asn1_mac.h is safe to drop.) Change-Id: Idb33dda8863bf1a3408b14d5513a667338311b6b Reviewed-on: https://boringssl-review.googlesource.com/4255 Reviewed-by: Adam Langley --- CMakeLists.txt | 2 +- ssl/s3_pkt.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c95b7e9..3baad513 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ elseif(MSVC) # 'unsigned long', signed/unsigned mismatch "C4267" # conversion from 'size_t' to 'int', possible loss of data "C4311" # 'type cast' : pointer truncation from 'uint8_t *' to 'long' - # TODO(davidben): Fix the s3_pkt.c's alignment code to avoid this. + # TODO(davidben): Remove this warning once asn1_add_error is gone. "C4371" # layout of class may have changed from a previous version of the # compiler due to better packing of member '...' "C4388" # signed/unsigned mismatch diff --git a/ssl/s3_pkt.c b/ssl/s3_pkt.c index 436e8300..80eb7bd6 100644 --- a/ssl/s3_pkt.c +++ b/ssl/s3_pkt.c @@ -133,7 +133,7 @@ int ssl3_read_n(SSL *s, int n, int max, int extend) { * bytes may be stored in |rbuf| (plus |s->packet_length| bytes if |extend| * is one.) */ int i, len, left; - long align = 0; + uintptr_t align = 0; uint8_t *pkt; SSL3_BUFFER *rb; @@ -148,8 +148,8 @@ int ssl3_read_n(SSL *s, int n, int max, int extend) { left = rb->left; - align = (long)rb->buf + SSL3_RT_HEADER_LENGTH; - align = (-align) & (SSL3_ALIGN_PAYLOAD - 1); + align = (uintptr_t)rb->buf + SSL3_RT_HEADER_LENGTH; + align = (0 - align) & (SSL3_ALIGN_PAYLOAD - 1); if (!extend) { /* start with empty packet ... */ @@ -604,7 +604,7 @@ static int do_ssl3_write(SSL *s, int type, const uint8_t *buf, unsigned int len, } else { align = (uintptr_t)wb->buf + SSL3_RT_HEADER_LENGTH; } - align = (-align) & (SSL3_ALIGN_PAYLOAD - 1); + align = (0 - align) & (SSL3_ALIGN_PAYLOAD - 1); uint8_t *out = wb->buf + align; wb->offset = align; size_t max_out = wb->len - wb->offset;