Fix minor issues found by Clang's analysis.
Thanks to Denis Denisov for running the analysis.
Change-Id: I80810261e013423e746fd8d8afefb3581cffccc0
Reviewed-on: https://boringssl-review.googlesource.com/1701
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/bio/bio_mem.c b/crypto/bio/bio_mem.c
index 457c2e0..6e90db5 100644
--- a/crypto/bio/bio_mem.c
+++ b/crypto/bio/bio_mem.c
@@ -132,13 +132,12 @@
}
static int mem_read(BIO *bio, char *out, int outl) {
- int ret = -1;
- BUF_MEM *b;
+ int ret;
+ BUF_MEM *b = (BUF_MEM*) bio->ptr;
- b = (BUF_MEM *)bio->ptr;
BIO_clear_retry_flags(bio);
ret = outl;
- if (ret > (int)b->length) {
+ if (b->length < INT_MAX && ret > (int)b->length) {
ret = b->length;
}
diff --git a/crypto/ec/wnaf.c b/crypto/ec/wnaf.c
index b86107d..2fed4a5 100644
--- a/crypto/ec/wnaf.c
+++ b/crypto/ec/wnaf.c
@@ -448,8 +448,6 @@
wNAF[num] = tmp_wNAF;
wNAF[num + 1] = NULL;
wNAF_len[num] = tmp_len;
- if (tmp_len > max_len)
- max_len = tmp_len;
/* pre_comp->points starts with the points that we need here: */
val_sub[num] = pre_comp->points;
} else {
diff --git a/crypto/ecdsa/ecdsa.c b/crypto/ecdsa/ecdsa.c
index 067fd6c..ddc3e61 100644
--- a/crypto/ecdsa/ecdsa.c
+++ b/crypto/ecdsa/ecdsa.c
@@ -140,8 +140,9 @@
}
/* check input values */
- if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL ||
- (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) {
+ if ((group = EC_KEY_get0_group(eckey)) == NULL ||
+ (pub_key = EC_KEY_get0_public_key(eckey)) == NULL ||
+ sig == NULL) {
OPENSSL_PUT_ERROR(ECDSA, ECDSA_do_verify, ECDSA_R_MISSING_PARAMETERS);
return 0;
}
diff --git a/crypto/evp/example_sign.c b/crypto/evp/example_sign.c
index 847330d..9d2a296 100644
--- a/crypto/evp/example_sign.c
+++ b/crypto/evp/example_sign.c
@@ -127,9 +127,13 @@
fprintf(stderr, "sig_len mismatch\n");
goto out;
}
+
sig = malloc(sig_len);
- if (sig == NULL ||
- EVP_DigestSignFinal(&md_ctx, sig, &sig_len) != 1) {
+ if (sig == NULL) {
+ goto out;
+ }
+ if (EVP_DigestSignFinal(&md_ctx, sig, &sig_len) != 1) {
+ free(sig);
goto out;
}
diff --git a/crypto/internal.h b/crypto/internal.h
index 39d35ad..65a52ed 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -111,6 +111,10 @@
#include <openssl/ex_data.h>
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
/* st_CRYPTO_EX_DATA_IMPL contains an ex_data implementation. See the comments
* in ex_data.h for details of the behaviour of each of the functions. */