Commit 7e61b44404f0ed410c83cfd3947a52e88ae044e1

Authored by Loic Dachary
2 parents d61b4d37 128bd51f
Exists in v3

Merge branch 'wip-signed-integer-overflow-cppcheck-v3' into 'v3'

Resolve cppcheck Signed integer overflow errors

See merge request !22
include/gf_w32.h
... ... @@ -14,7 +14,7 @@
14 14 #include <stdint.h>
15 15  
16 16 #define GF_FIELD_WIDTH (32)
17   -#define GF_FIRST_BIT (1 << 31)
  17 +#define GF_FIRST_BIT ((gf_val_32_t)1 << 31)
18 18  
19 19 #define GF_BASE_FIELD_WIDTH (16)
20 20 #define GF_BASE_FIELD_SIZE (1 << GF_BASE_FIELD_WIDTH)
... ...
src/gf_general.c
... ... @@ -137,7 +137,7 @@ int gf_general_s_to_val(gf_general_t *v, int w, char *s, int hex)
137 137 }
138 138 if (w == 32) return 1;
139 139 if (w == 31) {
140   - if (v->w32 & (1 << 31)) return 0;
  140 + if (v->w32 & ((gf_val_32_t)1 << 31)) return 0;
141 141 return 1;
142 142 }
143 143 if (v->w32 & ~((1 << w)-1)) return 0;
... ...
src/gf_w128.c
... ... @@ -413,7 +413,7 @@ gf_w128_sse_bytwo_p_multiply(gf_t *gf, gf_val_128_t a128, gf_val_128_t b128, gf_
413 413 }
414 414 amask = _mm_srli_epi64(amask, 1); /*so does this one, but we can just replace after loop*/
415 415 }
416   - amask = _mm_insert_epi32(amask, 1 << 31, 0x1);
  416 + amask = _mm_insert_epi32(amask, (gf_val_32_t)1 << 31, 0x1);
417 417 for (i = 64; i < 128; i++) {
418 418 topbit = (_mm_extract_epi32(prod, 0x3) & pmask);
419 419 middlebit = (_mm_extract_epi32(prod, 0x1) & pmask);
... ...
src/gf_w32.c
... ... @@ -1079,7 +1079,7 @@ gf_w32_bytwo_p_sse_multiply_region(gf_t *gf, void *src, void *dest, gf_val_32_t
1079 1079 vrev = 0;
1080 1080 for (i = 0; i < 32; i++) {
1081 1081 vrev <<= 1;
1082   - if (!(val & (1 << i))) vrev |= 1;
  1082 + if (!(val & ((gf_val_32_t)1 << i))) vrev |= 1;
1083 1083 }
1084 1084  
1085 1085 s8 = (uint8_t *) rd.s_start;
... ...