Merge pull request #218 from libtom/pr/fix-clang-static-analyzer-warnings

Clang static analyzer warnings/errors - related to #217
This commit is contained in:
karel-m 2017-05-11 22:55:39 +02:00 committed by GitHub
commit c2bb38555e
7 changed files with 12 additions and 8 deletions

View File

@ -104,7 +104,7 @@ static void check_file(int argn, int argc, char **argv)
space++; space++;
for (n = 0; n < (buf + sizeof(buf)) - space; ++n) { for (n = 0; n < (buf + sizeof(buf)) - space; ++n) {
if(iscntrl(space[n])) { if(iscntrl((int)space[n])) {
space[n] = '\0'; space[n] = '\0';
break; break;
} }

View File

@ -723,6 +723,10 @@ void gcm_gen(void)
printf("Error GCM'ing: %s\n", error_to_string(err)); printf("Error GCM'ing: %s\n", error_to_string(err));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (len == 0) {
printf("Error GCM'ing: zero length\n");
exit(EXIT_FAILURE);
}
fprintf(out, "%3d: ", y1); fprintf(out, "%3d: ", y1);
for (z = 0; z < y1; z++) { for (z = 0; z < y1; z++) {
fprintf(out, "%02X", plaintext[z]); fprintf(out, "%02X", plaintext[z]);

View File

@ -899,7 +899,7 @@ int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
{ {
int N, R, i, pos, r; int N, R, i, pos, r;
ulong32 kappa[MAX_N]; ulong32 kappa[MAX_N];
ulong32 inter[MAX_N]; ulong32 inter[MAX_N] = { 0 }; /* initialize as all zeroes */
ulong32 v, K0, K1, K2, K3; ulong32 v, K0, K1, K2, K3;
LTC_ARGCHK(key != NULL); LTC_ARGCHK(key != NULL);

View File

@ -144,7 +144,7 @@ int ccm_memory(int cipher,
} }
/* initialize buffer for pt */ /* initialize buffer for pt */
if (direction == CCM_DECRYPT) { if (direction == CCM_DECRYPT && ptlen > 0) {
pt_work = XMALLOC(ptlen); pt_work = XMALLOC(ptlen);
if (pt_work == NULL) { if (pt_work == NULL) {
goto error; goto error;

View File

@ -49,7 +49,7 @@ static int char_to_int(unsigned char x)
int der_decode_utctime(const unsigned char *in, unsigned long *inlen, int der_decode_utctime(const unsigned char *in, unsigned long *inlen,
ltc_utctime *out) ltc_utctime *out)
{ {
unsigned char buf[32]; unsigned char buf[32] = { 0 }; /* initialize as all zeroes */
unsigned long x; unsigned long x;
int y; int y;

View File

@ -530,7 +530,6 @@ for (cnt = 0; cnt < len; ) {
for (i = 0; i < 9; ++i) { for (i = 0; i < 9; ++i) {
len = sizeof(in); len = sizeof(in);
len2 = sizeof(out); len2 = sizeof(out);
cnt = rsa_get_size(&key);
/* (1) */ /* (1) */
DO(rsa_sign_hash_ex(p, 20, p2, &len2, LTC_PKCS_1_V1_5, &yarrow_prng, prng_idx, hash_idx, 8, &privKey)); DO(rsa_sign_hash_ex(p, 20, p2, &len2, LTC_PKCS_1_V1_5, &yarrow_prng, prng_idx, hash_idx, 8, &privKey));
/* (2) */ /* (2) */
@ -540,7 +539,8 @@ for (cnt = 0; cnt < len; ) {
/* (3) */ /* (3) */
DO(ltc_mp.rsa_me(p2, len2, p3, &len3, PK_PUBLIC, &key)); DO(ltc_mp.rsa_me(p2, len2, p3, &len3, PK_PUBLIC, &key));
/* (4) */ /* (4) */
#if 0 #ifdef LTC_TEST_DBG
cnt = rsa_get_size(&key);
printf("\nBefore:"); printf("\nBefore:");
for (cnt = 0; cnt < len3; ++cnt) { for (cnt = 0; cnt < len3; ++cnt) {
if (cnt%32 == 0) if (cnt%32 == 0)
@ -563,7 +563,7 @@ for (cnt = 0; cnt < len; ) {
for (cnt = cnt + len3-cnt2+i; cnt < len; ++cnt) { for (cnt = cnt + len3-cnt2+i; cnt < len; ++cnt) {
p3[cnt] = 0; p3[cnt] = 0;
} }
#if 0 #ifdef LTC_TEST_DBG
printf("\nAfter:"); printf("\nAfter:");
for (cnt = 0; cnt < len3; ++cnt) { for (cnt = 0; cnt < len3; ++cnt) {
if (cnt%32 == 0) if (cnt%32 == 0)

View File

@ -1487,7 +1487,7 @@ void time_macs_(unsigned long MAC_SIZE)
if (cipher_idx == -1 || hash_idx == -1) { if (cipher_idx == -1 || hash_idx == -1) {
fprintf(stderr, "Warning the MAC tests requires AES and SHA1 to operate... so sorry\n"); fprintf(stderr, "Warning the MAC tests requires AES and SHA1 to operate... so sorry\n");
return; exit(EXIT_FAILURE);
} }
yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng); yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng);