From d1b6bbf706b2628ab21cee2eb51a7cfe8cf04bcd Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Wed, 2 Sep 2015 19:11:51 +0200 Subject: add -Wsign-compare and address the warnings * (1 << w) are changed into ((uint32_t)1 << w) * int are changed into uint32_t gf.c: gf_composite_get_default_poly: a larger unsigned were assigned to unsigned integers in which case the type of the assigned variable is changed to be the same as the value assigned to it. gf_w16.c: GF_MULTBY_TWO setting the parameter to a variable instead of passing the expression resolves the warning for some reason. Signed-off-by: Loic Dachary --- src/Makefile.am | 2 +- src/gf.c | 4 ++-- src/gf_w128.c | 4 ++-- src/gf_w16.c | 5 +++-- src/gf_w32.c | 18 +++++++++--------- src/gf_w64.c | 8 ++++---- src/gf_wgen.c | 36 ++++++++++++++++++------------------ 7 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 240c1fe..a3bd37a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = subdir-objects AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -AM_CFLAGS = -O3 $(SIMD_FLAGS) -fPIC +AM_CFLAGS = -O3 $(SIMD_FLAGS) -fPIC -Wsign-compare lib_LTLIBRARIES = libgf_complete.la libgf_complete_la_SOURCES = gf.c gf_method.c gf_wgen.c gf_w4.c gf_w8.c gf_w16.c gf_w32.c \ diff --git a/src/gf.c b/src/gf.c index 01a385b..835fb12 100644 --- a/src/gf.c +++ b/src/gf.c @@ -119,7 +119,7 @@ void gf_error() uint64_t gf_composite_get_default_poly(gf_t *base) { gf_internal_t *h; - int rv; + uint64_t rv; h = (gf_internal_t *) base->scratch; if (h->w == 4) { @@ -584,7 +584,7 @@ uint32_t gf_bitmatrix_inverse(uint32_t y, int w, uint32_t pp) uint32_t mat[32], inv[32], mask; int i; - mask = (w == 32) ? 0xffffffff : (1 << w) - 1; + mask = (w == 32) ? 0xffffffff : ((uint32_t)1 << w) - 1; for (i = 0; i < w; i++) { mat[i] = y; diff --git a/src/gf_w128.c b/src/gf_w128.c index 81999cb..b1e3d92 100644 --- a/src/gf_w128.c +++ b/src/gf_w128.c @@ -49,7 +49,7 @@ void gf_w128_multiply_region_from_single(gf_t *gf, void *src, void *dest, gf_val_128_t val, int bytes, int xor) { - int i; + uint32_t i; gf_val_128_t s128; gf_val_128_t d128; uint64_t c128[2]; @@ -87,7 +87,7 @@ void gf_w128_clm_multiply_region_from_single(gf_t *gf, void *src, void *dest, gf_val_128_t val, int bytes, int xor) { - int i; + uint32_t i; gf_val_128_t s128; gf_val_128_t d128; gf_region_data rd; diff --git a/src/gf_w16.c b/src/gf_w16.c index ce47849..4e026b2 100644 --- a/src/gf_w16.c +++ b/src/gf_w16.c @@ -1218,7 +1218,7 @@ int gf_w16_split_init(gf_t *gf) struct gf_w16_split_8_8_data *d8; int i, j, exp, issse3; int isneon = 0; - uint32_t p, basep; + uint32_t p, basep, tmp; h = (gf_internal_t *) gf->scratch; @@ -1253,7 +1253,8 @@ int gf_w16_split_init(gf_t *gf) if (j&1) { d8->tables[exp][i][j] = d8->tables[exp][i][j^1] ^ p; } else { - d8->tables[exp][i][j] = GF_MULTBY_TWO(d8->tables[exp][i][j>>1]); + tmp = d8->tables[exp][i][j>>1]; + d8->tables[exp][i][j] = GF_MULTBY_TWO(tmp); } } } diff --git a/src/gf_w32.c b/src/gf_w32.c index 2e187fd..854a6e4 100644 --- a/src/gf_w32.c +++ b/src/gf_w32.c @@ -50,7 +50,7 @@ void gf_w32_multiply_region_from_single(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor) { - int i; + uint32_t i; uint32_t *s32; uint32_t *d32; @@ -75,7 +75,7 @@ void gf_w32_clm_multiply_region_from_single_2(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor) { - int i; + uint32_t i; uint32_t *s32; uint32_t *d32; @@ -125,7 +125,7 @@ void gf_w32_clm_multiply_region_from_single_3(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor) { - int i; + uint32_t i; uint32_t *s32; uint32_t *d32; @@ -178,7 +178,7 @@ static void gf_w32_clm_multiply_region_from_single_4(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor) { - int i; + uint32_t i; uint32_t *s32; uint32_t *d32; @@ -389,7 +389,7 @@ void gf_w32_cfmgk_multiply_region_from_single(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor) { - int i; + uint32_t i; uint32_t *s32; uint32_t *d32; @@ -666,12 +666,12 @@ static void gf_w32_group_set_shift_tables(uint32_t *shift, uint32_t val, gf_internal_t *h) { - int i; + uint32_t i; uint32_t j; shift[0] = 0; - for (i = 1; i < (1 << h->arg1); i <<= 1) { + for (i = 1; i < ((uint32_t)1 << h->arg1); i <<= 1) { for (j = 0; j < i; j++) shift[i|j] = shift[j]^val; if (val & GF_FIRST_BIT) { val <<= 1; @@ -2375,7 +2375,7 @@ int gf_w32_group_init(gf_t *gf) uint32_t i, j, p, index; struct gf_w32_group_data *gd; gf_internal_t *h = (gf_internal_t *) gf->scratch; - int g_r, g_s; + uint32_t g_r, g_s; g_s = h->arg1; g_r = h->arg2; @@ -2393,7 +2393,7 @@ int gf_w32_group_init(gf_t *gf) gd->tshift = ((gd->tshift-1)/g_r) * g_r; gd->reduce[0] = 0; - for (i = 0; i < (1 << g_r); i++) { + for (i = 0; i < ((uint32_t)1 << g_r); i++) { p = 0; index = 0; for (j = 0; j < g_r; j++) { diff --git a/src/gf_w64.c b/src/gf_w64.c index de231db..eae31e6 100644 --- a/src/gf_w64.c +++ b/src/gf_w64.c @@ -35,7 +35,7 @@ void gf_w64_multiply_region_from_single(gf_t *gf, void *src, void *dest, gf_val_64_t val, int bytes, int xor) { - int i; + uint32_t i; gf_val_64_t *s64; gf_val_64_t *d64; @@ -733,7 +733,7 @@ static void gf_w64_group_set_shift_tables(uint64_t *shift, uint64_t val, gf_internal_t *h) { - int i; + uint64_t i; uint64_t j; uint64_t one = 1; int g_s; @@ -741,7 +741,7 @@ gf_w64_group_set_shift_tables(uint64_t *shift, uint64_t val, gf_internal_t *h) g_s = h->arg1; shift[0] = 0; - for (i = 1; i < (1 << g_s); i <<= 1) { + for (i = 1; i < ((uint64_t)1 << g_s); i <<= 1) { for (j = 0; j < i; j++) shift[i|j] = shift[j]^val; if (val & (one << 63)) { val <<= 1; @@ -984,7 +984,7 @@ int gf_w64_group_init(gf_t *gf) uint64_t i, j, p, index; struct gf_w64_group_data *gd; gf_internal_t *h = (gf_internal_t *) gf->scratch; - int g_r, g_s; + uint64_t g_r, g_s; g_s = h->arg1; g_r = h->arg2; diff --git a/src/gf_wgen.c b/src/gf_wgen.c index 06f7993..ebc50a5 100644 --- a/src/gf_wgen.c +++ b/src/gf_wgen.c @@ -166,10 +166,10 @@ gf_wgen_shift_multiply (gf_t *gf, uint32_t a32, uint32_t b32) product = 0; - for (i = 0; i < h->w; i++) { + for (i = 0; i < (uint64_t)h->w; i++) { if (a & (one << i)) product ^= (b << i); } - for (i = h->w*2-1; i >= h->w; i--) { + for (i = h->w*2-1; i >= (uint64_t)h->w; i--) { if (product & (one << i)) product ^= (pp << (i-h->w)); } return product; @@ -256,7 +256,7 @@ static void gf_wgen_group_set_shift_tables(uint32_t *shift, uint32_t val, gf_internal_t *h) { - int i; + uint32_t i; uint32_t j; int g_s; @@ -268,7 +268,7 @@ gf_wgen_group_set_shift_tables(uint32_t *shift, uint32_t val, gf_internal_t *h) shift[0] = 0; - for (i = 1; i < (1 << g_s); i <<= 1) { + for (i = 1; i < ((uint32_t)1 << g_s); i <<= 1) { for (j = 0; j < i; j++) shift[i|j] = shift[j]^val; if (val & (1 << (h->w-1))) { val <<= 1; @@ -417,7 +417,7 @@ int gf_wgen_group_init(gf_t *gf) uint32_t i, j, p, index; struct gf_wgen_group_data *gd; gf_internal_t *h = (gf_internal_t *) gf->scratch; - int g_s, g_r; + uint32_t g_s, g_r; if (h->mult_type == GF_MULT_DEFAULT) { g_s = 2; @@ -440,7 +440,7 @@ int gf_wgen_group_init(gf_t *gf) gd->tshift = ((gd->tshift-1)/g_r) * g_r; gd->reduce[0] = 0; - for (i = 0; i < (1 << g_r); i++) { + for (i = 0; i < ((uint32_t)1 << g_r); i++) { p = 0; index = 0; for (j = 0; j < g_r; j++) { @@ -504,15 +504,15 @@ int gf_wgen_table_8_init(gf_t *gf) std->mult = &(std->base); std->div = std->mult + ((1<w)*(1<w)); - for (a = 0; a < (1 << w); a++) { + for (a = 0; a < ((uint32_t)1 << w); a++) { std->mult[a] = 0; std->mult[a<div[a] = 0; std->div[a<mult[(a<div[(p<mult = &(std->base); std->div = std->mult + ((1<w)*(1<w)); - for (a = 0; a < (1 << w); a++) { + for (a = 0; a < ((uint32_t)1 << w); a++) { std->mult[a] = 0; std->mult[a<div[a] = 0; std->div[a<mult[(a<div[(p<anti = std->log + (1<w); std->danti = std->anti + (1<w)-1; - for (i = 0; i < (1 << w); i++) + for (i = 0; i < ((uint32_t)1 << w); i++) std->log[i] = 0; a = 1; - for(i=0; i < (1<log[a] != 0) check = 1; std->log[a] = i; @@ -724,11 +724,11 @@ int gf_wgen_log_16_init(gf_t *gf) std->anti = std->log + (1<w); std->danti = std->anti + (1<w)-1; - for (i = 0; i < (1 << w); i++) + for (i = 0; i < ((uint32_t)1 << w); i++) std->log[i] = 0; a = 1; - for(i=0; i < (1<log[a] != 0) check = 1; std->log[a] = i; @@ -800,11 +800,11 @@ int gf_wgen_log_32_init(gf_t *gf) std->anti = std->log + (1<w); std->danti = std->anti + (1<w)-1; - for (i = 0; i < (1 << w); i++) + for (i = 0; i < ((uint32_t)1 << w); i++) std->log[i] = 0; a = 1; - for(i=0; i < (1<log[a] != 0) check = 1; std->log[a] = i; -- cgit v1.2.1