diff --git a/m-core.h b/m-core.h index 758c94c1..63752250 100644 --- a/m-core.h +++ b/m-core.h @@ -1913,11 +1913,11 @@ static inline uint64_t m_core_roundpow2(uint64_t v) #if defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__) >= 304 static inline unsigned int m_core_clz32(uint32_t limb) { - return M_UNLIKELY (limb == 0) ? sizeof(uint32_t)*CHAR_BIT : (unsigned int) __builtin_clzl(limb) - (sizeof(unsigned long) - sizeof(uint32_t)) * CHAR_BIT; + return (unsigned int) (M_UNLIKELY (limb == 0) ? sizeof(uint32_t)*CHAR_BIT : (size_t) __builtin_clzl(limb) - (sizeof(unsigned long) - sizeof(uint32_t)) * CHAR_BIT); } static inline unsigned int m_core_clz64(uint64_t limb) { - return M_UNLIKELY (limb == 0ULL) ? sizeof (uint64_t)*CHAR_BIT : (unsigned int) __builtin_clzll(limb) - (sizeof (unsigned long long) - sizeof (uint64_t)) * CHAR_BIT; + return (unsigned int) (M_UNLIKELY (limb == 0ULL) ? sizeof (uint64_t)*CHAR_BIT : (size_t) __builtin_clzll(limb) - (sizeof (unsigned long long) - sizeof (uint64_t)) * CHAR_BIT); } #elif defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_ARM64)) diff --git a/m-dict.h b/m-dict.h index bd76dc23..8feb97fe 100644 --- a/m-dict.h +++ b/m-dict.h @@ -1212,8 +1212,8 @@ typedef enum { static inline void \ M_C(name,_int_limit)(dict_t dict, size_t size) \ { \ - dict->upper_limit = (size_t) (size * coeff_up) - 1; \ - dict->lower_limit = (size <= DICTI_INITIAL_SIZE) ? 0 : (size_t) (size * coeff_down) ; \ + dict->upper_limit = (size_t) ((double) size * coeff_up) - 1; \ + dict->lower_limit = (size <= DICTI_INITIAL_SIZE) ? 0 : (size_t) ((double) size * coeff_down) ; \ } \ \ static inline void \ @@ -1856,14 +1856,14 @@ typedef enum { DICTI_OA_CONTRACT(dict); \ size_t size; \ /* Get the size which will allow to fit this capacity */ \ - size = m_core_roundpow2 ((uint64_t) (capacity * (1.0 / coeff_up))); \ + size = m_core_roundpow2 ((uint64_t) ((double) capacity * (1.0 / coeff_up))); \ /* Test for overflow of the computation */ \ if (M_UNLIKELY (size < capacity)) { \ M_MEMORY_FULL((size_t)-1); \ } \ assert (M_POWEROF2_P(size)); \ if (size > dict->mask+1) { \ - dict->upper_limit = (size_t) (size * coeff_up) - 1; \ + dict->upper_limit = (size_t) ((double) size * coeff_up) - 1; \ M_C(name,_int_resize_up)(dict, size, false); \ } \ DICTI_OA_CONTRACT(dict); \ diff --git a/m-genint.h b/m-genint.h index 87728f3b..28819d50 100644 --- a/m-genint.h +++ b/m-genint.h @@ -64,7 +64,7 @@ typedef struct genint_s { #define GENINT_MAX_ALLOC (GENINT_LIMBSIZE * (GENINT_LIMBSIZE - GENINT_ABA_CPT)) // Define the size of a limb in bits. -#define GENINT_LIMBSIZE (sizeof(genint_limb_t) * CHAR_BIT) +#define GENINT_LIMBSIZE ((unsigned)(sizeof(genint_limb_t) * CHAR_BIT)) // Define the contract of a genint #define GENINT_CONTRACT(s) do { \ diff --git a/m-rbtree.h b/m-rbtree.h index 861ea85f..a606d5d8 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -326,7 +326,7 @@ typedef enum { } else { \ /* go left (if cmp > 0) or right (if cmp < 0) */ \ int s = (cmp < 0); \ - which[cpt++] = s; \ + which[cpt++] = (int8_t) s; \ n = n->child[s]; \ } \ /* We cannot overflow the max depth of a tree */ \ @@ -433,13 +433,13 @@ typedef enum { assert (child == 0 || child == 1); \ unsigned int cpt = 0; \ if (tree->node != NULL) { \ - it->which[cpt] = child; \ + it->which[cpt] = (int8_t) child; \ node_t *n = it->stack[cpt++] = tree->node; \ /* Go down the tree and fill in the iterator */ \ while (n->child[child] != NULL) { \ assert (cpt < RBTREEI_MAX_STACK); \ n = n->child[child]; \ - it->which[cpt] = child; \ + it->which[cpt] = (int8_t) child; \ it->stack[cpt++] = n; \ } \ assert (n == it->stack[cpt - 1]); \ @@ -496,14 +496,14 @@ typedef enum { /* Going right */ \ assert (cpt < RBTREEI_MAX_STACK); \ n = n->child[right]; \ - it->which[cpt++] = right; \ + it->which[cpt++] = (int8_t) right; \ it->stack[cpt] = n; \ - it->which[cpt++] = child; \ + it->which[cpt++] = (int8_t) child; \ /* Going left */ \ while (n->child[child] != NULL) { \ assert (cpt < RBTREEI_MAX_STACK); \ n = n->child[child]; \ - it->which[cpt] = child; \ + it->which[cpt] = (int8_t) child; \ it->stack[cpt++] = n; \ } \ assert (n == it->stack[cpt - 1]); \ @@ -562,7 +562,7 @@ typedef enum { if (cmp == 0) \ break; \ int child = (cmp < 0); \ - it->which[cpt++] = child; \ + it->which[cpt++] = (int8_t) child; \ n = n->child[child]; \ assert (cpt < RBTREEI_MAX_STACK); \ it->stack[cpt] = n; \ @@ -800,7 +800,7 @@ typedef enum { break; \ } \ int i = (cmp < 0); \ - which[cpt++] = i; \ + which[cpt++] = (int8_t) i; \ n = n->child[i]; \ assert (cpt < RBTREEI_MAX_STACK); \ tab[cpt] = n; \ diff --git a/m-string.h b/m-string.h index c495af79..ebaa89ca 100644 --- a/m-string.h +++ b/m-string.h @@ -1100,9 +1100,9 @@ string_get_str(string_t v, const string_t v2, bool append) ptr = stringi_fit2size(v, targetSize); int d1 = c & 0x07, d2 = (c>>3) & 0x07, d3 = (c>>6) & 0x07; ptr[size ++] = '\\'; - ptr[size ++] = '0' + d3; - ptr[size ++] = '0' + d2; - ptr[size ++] = '0' + d1; + ptr[size ++] = (char) ('0' + d3); + ptr[size ++] = (char) ('0' + d2); + ptr[size ++] = (char) ('0' + d1); } else { ptr[size ++] = c; } @@ -1193,7 +1193,7 @@ string_in_str(string_t v, FILE *f) break; } } - string_push_back (v, c); + string_push_back (v, (char) c); c = fgetc(f); } return c == '"'; @@ -1243,7 +1243,7 @@ string_parse_str(string_t v, const char str[], const char **endptr) break; } } - string_push_back (v, c); + string_push_back (v, (char) c); c = *str++; } success = (c == '"'); @@ -1326,7 +1326,7 @@ static inline void stringi_utf8_decode(char c, stringi_utf8_state_e *state, string_unicode_t *unicode) { - const unsigned int type = m_core_clz32((unsigned char)~c) - (sizeof(uint32_t) - 1) * CHAR_BIT; + const unsigned int type = m_core_clz32((unsigned char)~c) - (unsigned) (sizeof(uint32_t) - 1) * CHAR_BIT; const string_unicode_t mask1 = (UINT_MAX - (string_unicode_t)(*state != STRINGI_UTF8_STARTING) + 1); const string_unicode_t mask2 = (0xFFU >> type); *unicode = ((*unicode << 6) & mask1) | ((unsigned int) c & mask2); diff --git a/m-variant.h b/m-variant.h index aabf0d9c..c28833ed 100644 --- a/m-variant.h +++ b/m-variant.h @@ -501,7 +501,7 @@ /* First read the name of the type */ \ c = *str++; \ while (c != '@' && c != 0 && i < sizeof(variantTypeBuf) - 1) { \ - variantTypeBuf[i++] = c; \ + variantTypeBuf[i++] = (char) c; \ c = *str++; \ } \ if (c != '@') goto exit; \ @@ -559,7 +559,7 @@ int c = fgetc(f); \ unsigned int i = 0; \ while (c != '@' && c != EOF && i < sizeof(variantTypeBuf) - 1) { \ - variantTypeBuf[i++] = c; \ + variantTypeBuf[i++] = (char) c; \ c = fgetc(f); \ } \ if (c != '@') return false; \ diff --git a/m-worker.h b/m-worker.h index b701e723..dc5c3dc1 100644 --- a/m-worker.h +++ b/m-worker.h @@ -192,7 +192,7 @@ workeri_get_cpu_count(void) sysctl(nm, 2, &count, &len, NULL, 0); return M_MAX(1, count); #elif defined (_SC_NPROCESSORS_ONLN) - return sysconf(_SC_NPROCESSORS_ONLN); + return (int) sysconf(_SC_NPROCESSORS_ONLN); #else return 1; #endif diff --git a/tests/Makefile b/tests/Makefile index 2f0a6cd3..d509c172 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,8 +21,8 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. CC=cc -std=c99 -WCFLAGS_GCC=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wunused-function -ftrapv -Wsign-conversion -WCFLAGS_CLANG=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wunused-function -ftrapv -Wsign-conversion +WCFLAGS_GCC=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wunused-function -ftrapv -Wsign-conversion -Wdate-time -Wconversion -Wformat=2 -Winit-self -Wjump-misses-init -Wstack-protector -Wtrampolines -Wwrite-strings -Wformat-security +WCFLAGS_CLANG=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wunused-function -ftrapv -Wsign-conversion WCFLAGS_CPP=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wstrict-overflow=5 -Winline -Wundef -Wcast-qual -Wshadow -Wunreachable-code -Wstrict-aliasing=2 -Wredundant-decls -Wunused-function -ftrapv -Wsign-conversion XCFLAGS= CFLAGS=$(WCFLAGS_GCC) $(XCFLAGS) diff --git a/tests/test-mbuffer.c b/tests/test-mbuffer.c index c42def89..bf131003 100644 --- a/tests/test-mbuffer.c +++ b/tests/test-mbuffer.c @@ -179,7 +179,7 @@ static void test_stack2(void) char c; buffer_char_init(buff, 10); for(int i = 0; i < 10; i++) { - c = i; + c = (char) i; b = buffer_char_push(buff, c); assert (b == true); assert (buffer_char_empty_p(buff) == false); @@ -307,8 +307,9 @@ static void test_prod(void *arg) assert (arg == NULL); for(unsigned int i = 0; i < 10;i++) { test_t *p = test_new(); - for(int j = 0; j < 52; j++) - p->buffer[j] = (j * j * 17) + j * 42 + 1; + for(int j = 0; j < 52; j++) { + p->buffer[j] = (char) ((j * j * 17) + j * 42 + 1); + } buffer_itest_push(comm1, p); buffer_itest_push(comm2, p); ishared_itest_clear(p); diff --git a/tests/test-mcore.c b/tests/test-mcore.c index 0fead026..5df4c26c 100644 --- a/tests/test-mcore.c +++ b/tests/test-mcore.c @@ -469,14 +469,14 @@ static void test_builtin(void) { assert(m_core_clz32(0) == 32); for(unsigned i = 0; i < 31; i++) { - assert(m_core_clz32(1UL<