From cc6da8941c7a9ee3210e45f59309943196a55e95 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 22 Jun 2020 00:14:37 +0200 Subject: [PATCH] * Fix wanings for reduce precision on integers. * Add wrapper for strncat --- m-buffer.h | 12 ++++++------ m-core.h | 10 +++++++--- m-snapshot.h | 4 ++-- m-string.h | 2 +- m-worker.h | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/m-buffer.h b/m-buffer.h index 56fa269b..56c939f6 100644 --- a/m-buffer.h +++ b/m-buffer.h @@ -706,17 +706,17 @@ M_C(name, _init)(buffer_t v, size_t size) \ { \ assert (buffer != NULL); \ assert( M_POWEROF2_P(size)); \ - assert (size < UINT_MAX); \ + assert (0 < size && size <= UINT_MAX); \ assert(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \ atomic_init(&buffer->ProdIdx, (unsigned int) size); \ atomic_init(&buffer->ConsoIdx, (unsigned int) size); \ - buffer->size = size; \ + buffer->size = (unsigned int) size; \ buffer->Tab = M_CALL_REALLOC(oplist, M_C(name, _el_t), NULL, size); \ if (buffer->Tab == NULL) { \ M_MEMORY_FULL (size*sizeof(M_C(name, _el_t) )); \ return; \ } \ - for(unsigned int j = 0; j < size; j++) { \ + for(unsigned int j = 0; j < (unsigned int) size; j++) { \ atomic_init(&buffer->Tab[j].seq, 2*j+1U); \ if (!BUFFERI_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ M_CALL_INIT(oplist, buffer->Tab[j].x); \ @@ -1022,18 +1022,18 @@ M_C(name, _init)(buffer_t v, size_t size) \ { \ assert (buffer != NULL); \ assert( M_POWEROF2_P(size)); \ - assert (size < UINT_MAX); \ + assert (0 < size && size <= UINT_MAX); \ assert(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \ atomic_init(&buffer->prodIdx, (unsigned int) size); \ atomic_init(&buffer->consoIdx, (unsigned int) size); \ - buffer->size = size; \ + buffer->size = (unsigned int) size; \ buffer->Tab = M_CALL_REALLOC(oplist, M_C(name, _el_t), NULL, size); \ if (buffer->Tab == NULL) { \ M_MEMORY_FULL (size*sizeof(M_C(name, _el_t) )); \ return; \ } \ if (!BUFFERI_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ - for(size_t j = 0; j < size; j++) { \ + for(unsigned int j = 0; j < (unsigned int) size; j++) { \ M_CALL_INIT(oplist, buffer->Tab[j].x); \ } \ } \ diff --git a/m-core.h b/m-core.h index 3aa4a2eb..bac9112a 100644 --- a/m-core.h +++ b/m-core.h @@ -1476,6 +1476,7 @@ * - fopen * - fscanf * - strncpy + * - strncat * * There is no real usage outside of MSVS of Annex K, * so the real standard compliant Annex K is not taken into account @@ -1485,9 +1486,8 @@ * and the user wants to use the Annex K. * ==> Use Annex K like functions to avoid warnings * - * Only fscanf, fopen and strncpy produce warning, - * so we keep the wrapper as simple as possible by including only - * theses functions. + * Only these functions produce warning, + * so we keep the wrapper as simple as possible by including only then. */ #if defined(_MSC_VER) && defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ @@ -1502,6 +1502,8 @@ m_core_fopen(const char filename[], const char opt[]) } /* Wrapper around strncpy_s */ #define m_core_strncpy(s1, s2, size) strncpy_s(s1, size, s2, size) +/* Wrapper around strncat_s */ +#define m_core_strncat(s1, s2, size) strncat_s(s1, size, s2, size) /* Wrapper around fscanf_s */ #define m_core_fscanf(...) fscanf_s(__VA_ARGS__) @@ -1516,6 +1518,8 @@ m_core_fopen(const char filename[], const char opt[]) #define m_core_fopen(...) fopen(__VA_ARGS__) /* Wrapper around strncpy */ #define m_core_strncpy(...) strncpy(__VA_ARGS__) +/* Wrapper around strncat */ +#define m_core_strncat(s1, s2, size) strncat(s1, s2, size) /* Wrapper around fscanf */ #define m_core_fscanf(...) fscanf(__VA_ARGS__) diff --git a/m-snapshot.h b/m-snapshot.h index 7f99b7cb..c8266c1a 100644 --- a/m-snapshot.h +++ b/m-snapshot.h @@ -341,7 +341,7 @@ static inline void snapshot_mrsw_int_init(snapshot_mrsw_int_t s, size_t n) s->cptTab = ptr; for(size_t i = 0; i < n; i++) atomic_init(&s->cptTab[i], 0U); - genint_init (s->freeList, n); + genint_init (s->freeList, (unsigned int) n); // Get a free buffer and set it as available for readers unsigned int w = genint_pop(s->freeList); assert (w != GENINT_ERROR); @@ -372,7 +372,7 @@ static inline unsigned int snapshot_mrsw_int_get_write_idx(snapshot_mrsw_int_t s static inline unsigned int snapshot_mrsw_int_size(snapshot_mrsw_int_t s) { SNAPSHOTI_SPMC_INT_CONTRACT(s); - return s->n; + return (unsigned int) s->n; } static inline unsigned int snapshot_mrsw_int_write_idx(snapshot_mrsw_int_t s, unsigned int idx) diff --git a/m-string.h b/m-string.h index 2c9a23be..10d35cf6 100644 --- a/m-string.h +++ b/m-string.h @@ -1884,7 +1884,7 @@ namespace m_string { BOUNDED_STRINGI_CONTRACT(s, max_size); \ assert (str != NULL); \ assert (strlen(s->s) <= max_size); \ - strncat(s->s, str, max_size-strlen(s->s)); \ + m_core_strncat(s->s, str, max_size-strlen(s->s)); \ } \ \ static inline void \ diff --git a/m-worker.h b/m-worker.h index 36476238..2196fd5e 100644 --- a/m-worker.h +++ b/m-worker.h @@ -285,7 +285,7 @@ worker_init(worker_t g, int numWorker, unsigned int extraQueue, void (*resetFunc return; } worker_queue_init(g->queue_g, numWorker_st + extraQueue); - g->numWorker_g = numWorker_st; + g->numWorker_g = (unsigned int) numWorker_st; g->resetFunc_g = resetFunc; g->clearFunc_g = clearFunc; m_mutex_init(g->lock);