Skip to content

Commit

Permalink
Fix all sign/unsigned warnings with Clang and GCC.
Browse files Browse the repository at this point in the history
Change-Id: If2a83698236f7b0dcd46701ccd257a85463d6ce5
Reviewed-on: https://boringssl-review.googlesource.com/4992
Reviewed-by: Adam Langley <[email protected]>
  • Loading branch information
agl committed Oct 27, 2015
1 parent 0dc2a8a commit 96c2a28
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ if (NOT GO_EXECUTABLE)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -ggdb -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -ggdb -std=c++0x -fvisibility=hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wsign-compare -ggdb -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wsign-compare -ggdb -std=c++0x -fvisibility=hidden")
elseif(MSVC)
set(MSVC_DISABLED_WARNINGS_LIST
"C4100" # 'exarg' : unreferenced formal parameter
Expand Down
10 changes: 6 additions & 4 deletions crypto/bio/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
uint8_t header[6];

static const size_t kInitialHeaderLen = 2;
if (BIO_read(bio, header, kInitialHeaderLen) != kInitialHeaderLen) {
if (BIO_read(bio, header, kInitialHeaderLen) != (int) kInitialHeaderLen) {
return 0;
}

Expand Down Expand Up @@ -559,7 +559,8 @@ int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
return 0;
}

if (BIO_read(bio, header + kInitialHeaderLen, num_bytes) != num_bytes) {
if (BIO_read(bio, header + kInitialHeaderLen, num_bytes) !=
(int)num_bytes) {
return 0;
}
header_len = kInitialHeaderLen + num_bytes;
Expand All @@ -585,7 +586,8 @@ int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
}

if (len + header_len < len ||
len + header_len > max_len) {
len + header_len > max_len ||
len > INT_MAX) {
return 0;
}
len += header_len;
Expand All @@ -597,7 +599,7 @@ int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
}
memcpy(*out, header, header_len);
if (BIO_read(bio, (*out) + header_len, len - header_len) !=
len - header_len) {
(int) (len - header_len)) {
OPENSSL_free(*out);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/bio/bio_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static int mem_write(BIO *bio, const char *in, int inl) {
if (INT_MAX - blen < inl) {
goto err;
}
if (BUF_MEM_grow_clean(b, blen + inl) != (blen + inl)) {
if (BUF_MEM_grow_clean(b, blen + inl) != ((size_t) blen) + inl) {
goto err;
}
memcpy(&b->data[blen], in, inl);
Expand Down
6 changes: 5 additions & 1 deletion crypto/bio/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ int BIO_printf(BIO *bio, const char *format, ...) {
}
#endif

if (out_len >= sizeof(buf)) {
if (out_len < 0) {
return -1;
}

if ((size_t) out_len >= sizeof(buf)) {
const int requested_len = out_len;
/* The output was truncated. Note that vsnprintf's return value
* does not include a trailing NUL, but the buffer must be sized
Expand Down
2 changes: 1 addition & 1 deletion crypto/dh/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ DH *DH_get_2048_256(const ENGINE *engine) {
}

void DH_check_standard_parameters(DH *dh) {
int i;
unsigned i;

if (dh->p == NULL ||
dh->g == NULL ||
Expand Down
2 changes: 1 addition & 1 deletion crypto/ec/ec_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ EC_GROUP *ec_asn1_pkparameters2group(const ECPKPARAMETERS *params) {
for (i = 0; OPENSSL_built_in_curves[i].nid != NID_undef; i++) {
curve = &OPENSSL_built_in_curves[i];
const unsigned param_len = curve->data->param_len;
if (ecparams->order->length == param_len &&
if ((unsigned) ecparams->order->length == param_len &&
memcmp(ecparams->order->data, &curve->data->data[param_len * 5],
param_len) == 0) {
nid = curve->nid;
Expand Down
2 changes: 1 addition & 1 deletion crypto/err/err_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static bool TestOverflow() {
/* Errors are returned in order they were pushed, with the least recent ones
* removed, up to |ERR_NUM_ERRORS - 1| errors. So the errors returned are
* |ERR_NUM_ERRORS + 2| through |ERR_NUM_ERRORS * 2|, inclusive. */
if (err == 0 || ERR_GET_REASON(err) != i + ERR_NUM_ERRORS + 2) {
if (err == 0 || ((unsigned)ERR_GET_REASON(err)) != i + ERR_NUM_ERRORS + 2) {
fprintf(stderr, "ERR_get_error failed at %u\n", i);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/pem/pem_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe
if (xi != NULL) X509_INFO_free(xi);
if (!ok)
{
for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
for (i=0; i<sk_X509_INFO_num(ret); i++)
{
xi=sk_X509_INFO_value(ret,i);
X509_INFO_free(xi);
Expand Down
2 changes: 1 addition & 1 deletion crypto/pkcs8/p5_pbev2.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ static int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx,
}

const size_t iv_len = EVP_CIPHER_CTX_iv_length(ctx);
if (iv->value.octet_string->length != iv_len) {
if ((size_t) iv->value.octet_string->length != iv_len) {
OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_ERROR_SETTING_CIPHER_PARAMS);
goto err;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/rsa/rsa_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ static int keygen_multiprime(RSA *rsa, int bits, int num_primes,
if (!BN_mul(r1, rsa->n, ap->prime, ctx)) {
goto err;
}
if (BN_num_bits(r1) == bits) {
if (BN_num_bits(r1) == (unsigned) bits) {
break;
}

Expand Down
2 changes: 1 addition & 1 deletion crypto/x509/x509_vfy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl,
int cidx = ctx->error_depth;
size_t i;

if (cidx != sk_X509_num(ctx->chain) - 1)
if ((size_t) cidx != sk_X509_num(ctx->chain) - 1)
cidx++;

crl_issuer = sk_X509_value(ctx->chain, cidx);
Expand Down
2 changes: 1 addition & 1 deletion crypto/x509v3/pcy_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static int tree_link_unmatched(X509_POLICY_LEVEL *curr,
{
/* If mapping: matched if one child per expected policy set */
STACK_OF(ASN1_OBJECT) *expset = node->data->expected_policy_set;
if (node->nchild == sk_ASN1_OBJECT_num(expset))
if ((size_t) node->nchild == sk_ASN1_OBJECT_num(expset))
return 1;
/* Locate unmatched nodes */
for (i = 0; i < sk_ASN1_OBJECT_num(expset); i++)
Expand Down
5 changes: 3 additions & 2 deletions crypto/x509v3/tab_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
int main(void)
{
#if !defined(BORINGSSL_SHARED_LIBRARY)
int i, prev = -1, bad = 0;
unsigned i;
int prev = -1, bad = 0;
const X509V3_EXT_METHOD *const *tmp;
CRYPTO_library_init();
i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *);
Expand All @@ -89,7 +90,7 @@ int main(void)
tmp = standard_exts;
fprintf(stderr, "Extensions out of order!\n");
for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
printf("%d : %s\n", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
printf("%d : %s\n", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
return 1;
} else {
printf("PASS\n");
Expand Down
4 changes: 2 additions & 2 deletions ssl/d1_both.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static int dtls1_discard_fragment_body(SSL *s, size_t frag_len) {
while (frag_len > 0) {
size_t chunk = frag_len < sizeof(discard) ? frag_len : sizeof(discard);
int ret = dtls1_read_bytes(s, SSL3_RT_HANDSHAKE, discard, chunk, 0);
if (ret != chunk) {
if (ret != (int) chunk) {
return 0;
}
frag_len -= chunk;
Expand Down Expand Up @@ -525,7 +525,7 @@ static int dtls1_process_fragment(SSL *s) {
/* Read the body of the fragment. */
ret = dtls1_read_bytes(s, SSL3_RT_HANDSHAKE, frag->fragment + frag_off,
frag_len, 0);
if (ret != frag_len) {
if (ret != (int) frag_len) {
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
return -1;
Expand Down
3 changes: 2 additions & 1 deletion ssl/d1_srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ static int ssl_ctx_make_profiles(const char *profiles_string,
const SRTP_PROTECTION_PROFILE *p;

col = strchr(ptr, ':');
if (find_profile_by_name(ptr, &p, col ? col - ptr : strlen(ptr))) {
if (find_profile_by_name(ptr, &p,
col ? (size_t)(col - ptr) : strlen(ptr))) {
sk_SRTP_PROTECTION_PROFILE_push(profiles, p);
} else {
OPENSSL_PUT_ERROR(SSL, SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);
Expand Down
2 changes: 1 addition & 1 deletion ssl/ssl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
* compressionMethod [11] OCTET STRING OPTIONAL,
* srpUsername [12] OCTET STRING OPTIONAL, */

static const int kVersion = 1;
static const unsigned kVersion = 1;

static const int kTimeTag =
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 1;
Expand Down

0 comments on commit 96c2a28

Please sign in to comment.