Commit a6862d10c9db467148f20eef2c6445ac9afd94d8

Authored by Loic Dachary
2 parents ea75cdff 2700e1b9

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

Wip signed integer overflow cppcheck

Fix for cppcheck signed integer overflow errors

See merge request !21
include/gf_w32.h
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 #include <stdint.h> 14 #include <stdint.h>
15 15
16 #define GF_FIELD_WIDTH (32) 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 #define GF_BASE_FIELD_WIDTH (16) 19 #define GF_BASE_FIELD_WIDTH (16)
20 #define GF_BASE_FIELD_SIZE (1 << GF_BASE_FIELD_WIDTH) 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,7 +137,7 @@ int gf_general_s_to_val(gf_general_t *v, int w, char *s, int hex)
137 } 137 }
138 if (w == 32) return 1; 138 if (w == 32) return 1;
139 if (w == 31) { 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 return 1; 141 return 1;
142 } 142 }
143 if (v->w32 & ~((1 << w)-1)) return 0; 143 if (v->w32 & ~((1 << w)-1)) return 0;
@@ -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,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 amask = _mm_srli_epi64(amask, 1); /*so does this one, but we can just replace after loop*/ 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 for (i = 64; i < 128; i++) { 417 for (i = 64; i < 128; i++) {
418 topbit = (_mm_extract_epi32(prod, 0x3) & pmask); 418 topbit = (_mm_extract_epi32(prod, 0x3) & pmask);
419 middlebit = (_mm_extract_epi32(prod, 0x1) & pmask); 419 middlebit = (_mm_extract_epi32(prod, 0x1) & pmask);
@@ -1079,7 +1079,7 @@ gf_w32_bytwo_p_sse_multiply_region(gf_t *gf, void *src, void *dest, gf_val_32_t @@ -1079,7 +1079,7 @@ gf_w32_bytwo_p_sse_multiply_region(gf_t *gf, void *src, void *dest, gf_val_32_t
1079 vrev = 0; 1079 vrev = 0;
1080 for (i = 0; i < 32; i++) { 1080 for (i = 0; i < 32; i++) {
1081 vrev <<= 1; 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 s8 = (uint8_t *) rd.s_start; 1085 s8 = (uint8_t *) rd.s_start;