aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-10-17 10:38:51 -0400
committerDamjan Marion <dmarion@me.com>2018-10-23 13:06:46 +0000
commitb7b929931a07fbb27b43d5cd105f366c3e29807e (patch)
tree438681c89738802dbb5d339715b96ea2c31bafb4 /src/vppinfra
parentb9a4c445c1d4e9cdab476a8e1fb8a46ff0fc6080 (diff)
c11 safe string handling support
Change-Id: Ied34720ca5a6e6e717eea4e86003e854031b6eab Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/asm_x86.c2
-rw-r--r--src/vppinfra/bihash_16_8.h2
-rw-r--r--src/vppinfra/bihash_16_8_32.h2
-rw-r--r--src/vppinfra/bihash_24_8.h2
-rw-r--r--src/vppinfra/bihash_40_8.h2
-rw-r--r--src/vppinfra/bihash_48_8.h2
-rw-r--r--src/vppinfra/bihash_template.c30
-rw-r--r--src/vppinfra/cuckoo_8_8.h2
-rw-r--r--src/vppinfra/cuckoo_template.c12
-rw-r--r--src/vppinfra/dlist.h2
-rw-r--r--src/vppinfra/elf.c4
-rw-r--r--src/vppinfra/elf.h2
-rw-r--r--src/vppinfra/elog.c4
-rw-r--r--src/vppinfra/fheap.c2
-rw-r--r--src/vppinfra/fheap.h2
-rw-r--r--src/vppinfra/fifo.c2
-rw-r--r--src/vppinfra/flowhash_template.h2
-rw-r--r--src/vppinfra/format.c4
-rw-r--r--src/vppinfra/format.h4
-rw-r--r--src/vppinfra/graph.c2
-rw-r--r--src/vppinfra/hash.c6
-rw-r--r--src/vppinfra/hash.h2
-rw-r--r--src/vppinfra/heap.c2
-rw-r--r--src/vppinfra/heap.h2
-rw-r--r--src/vppinfra/lock.h4
-rw-r--r--src/vppinfra/maplog.c6
-rw-r--r--src/vppinfra/mem.h2
-rw-r--r--src/vppinfra/mem_dlmalloc.c4
-rw-r--r--src/vppinfra/memcpy_avx2.h2
-rw-r--r--src/vppinfra/memcpy_avx512.h2
-rw-r--r--src/vppinfra/memcpy_sse3.h2
-rw-r--r--src/vppinfra/mhash.c2
-rw-r--r--src/vppinfra/mheap.c12
-rw-r--r--src/vppinfra/phash.c2
-rw-r--r--src/vppinfra/phash.h2
-rw-r--r--src/vppinfra/pool.c3
-rw-r--r--src/vppinfra/qhash.c7
-rw-r--r--src/vppinfra/random_buffer.c2
-rw-r--r--src/vppinfra/serialize.c10
-rw-r--r--src/vppinfra/slist.c4
-rw-r--r--src/vppinfra/socket.c8
-rw-r--r--src/vppinfra/socket.h2
-rw-r--r--src/vppinfra/string.c19
-rw-r--r--src/vppinfra/string.h113
-rw-r--r--src/vppinfra/test_cuckoo_bihash.c2
-rw-r--r--src/vppinfra/test_elf.c4
-rw-r--r--src/vppinfra/test_heap.c2
-rw-r--r--src/vppinfra/test_maplog.c4
-rw-r--r--src/vppinfra/test_mheap.c2
-rw-r--r--src/vppinfra/test_qhash.c2
-rw-r--r--src/vppinfra/test_serialize.c2
-rw-r--r--src/vppinfra/test_time_range.c2
-rw-r--r--src/vppinfra/test_timing_wheel.c2
-rw-r--r--src/vppinfra/test_tw_timer.c30
-rw-r--r--src/vppinfra/test_vhash.c2
-rw-r--r--src/vppinfra/time.c2
-rw-r--r--src/vppinfra/time_range.c2
-rw-r--r--src/vppinfra/timer.c6
-rw-r--r--src/vppinfra/timing_wheel.c2
-rw-r--r--src/vppinfra/tw_timer_template.c10
-rw-r--r--src/vppinfra/unformat.c8
-rw-r--r--src/vppinfra/valloc.c12
-rw-r--r--src/vppinfra/vec.c4
-rw-r--r--src/vppinfra/vec.h8
-rw-r--r--src/vppinfra/vhash.c2
65 files changed, 272 insertions, 144 deletions
diff --git a/src/vppinfra/asm_x86.c b/src/vppinfra/asm_x86.c
index 16e41c249b1..e6e00ce5543 100644
--- a/src/vppinfra/asm_x86.c
+++ b/src/vppinfra/asm_x86.c
@@ -1500,7 +1500,7 @@ u8 * x86_insn_parse (x86_insn_parse_t * p, u8 * code_start)
/* Preserve global parse flags. */
parse_flags = p->flags & (X86_INSN_PARSE_32_BIT | X86_INSN_PARSE_64_BIT);
- memset (p, 0, sizeof (p[0]));
+ clib_memset (p, 0, sizeof (p[0]));
p->flags = parse_flags;
/* 64 implies 32 bit parsing. */
diff --git a/src/vppinfra/bihash_16_8.h b/src/vppinfra/bihash_16_8.h
index 5949e2b3549..f6515b8aea0 100644
--- a/src/vppinfra/bihash_16_8.h
+++ b/src/vppinfra/bihash_16_8.h
@@ -36,7 +36,7 @@ typedef struct
static inline int
clib_bihash_is_free_16_8 (clib_bihash_kv_16_8_t * v)
{
- /* Free values are memset to 0xff, check a bit... */
+ /* Free values are clib_memset to 0xff, check a bit... */
if (v->key[0] == ~0ULL && v->value == ~0ULL)
return 1;
return 0;
diff --git a/src/vppinfra/bihash_16_8_32.h b/src/vppinfra/bihash_16_8_32.h
index d30625da39a..3e83ad2c52f 100644
--- a/src/vppinfra/bihash_16_8_32.h
+++ b/src/vppinfra/bihash_16_8_32.h
@@ -38,7 +38,7 @@ typedef struct
static inline int
clib_bihash_is_free_16_8_32 (clib_bihash_kv_16_8_32_t * v)
{
- /* Free values are memset to 0xff, check a bit... */
+ /* Free values are clib_memset to 0xff, check a bit... */
if (v->key[0] == ~0ULL && v->value == ~0ULL)
return 1;
return 0;
diff --git a/src/vppinfra/bihash_24_8.h b/src/vppinfra/bihash_24_8.h
index c028352d0e9..6d1cdd310bd 100644
--- a/src/vppinfra/bihash_24_8.h
+++ b/src/vppinfra/bihash_24_8.h
@@ -36,7 +36,7 @@ typedef struct
static inline int
clib_bihash_is_free_24_8 (const clib_bihash_kv_24_8_t * v)
{
- /* Free values are memset to 0xff, check a bit... */
+ /* Free values are clib_memset to 0xff, check a bit... */
if (v->key[0] == ~0ULL && v->value == ~0ULL)
return 1;
return 0;
diff --git a/src/vppinfra/bihash_40_8.h b/src/vppinfra/bihash_40_8.h
index fe57ba03966..b85adb09712 100644
--- a/src/vppinfra/bihash_40_8.h
+++ b/src/vppinfra/bihash_40_8.h
@@ -37,7 +37,7 @@ typedef struct
static inline int
clib_bihash_is_free_40_8 (const clib_bihash_kv_40_8_t * v)
{
- /* Free values are memset to 0xff, check a bit... */
+ /* Free values are clib_memset to 0xff, check a bit... */
if (v->key[0] == ~0ULL && v->value == ~0ULL)
return 1;
return 0;
diff --git a/src/vppinfra/bihash_48_8.h b/src/vppinfra/bihash_48_8.h
index 9aebe66d264..328a90b0fd4 100644
--- a/src/vppinfra/bihash_48_8.h
+++ b/src/vppinfra/bihash_48_8.h
@@ -37,7 +37,7 @@ typedef struct
static inline int
clib_bihash_is_free_48_8 (const clib_bihash_kv_48_8_t * v)
{
- /* Free values are memset to 0xff, check a bit... */
+ /* Free values are clib_memset to 0xff, check a bit... */
if (v->key[0] == ~0ULL && v->value == ~0ULL)
return 1;
return 0;
diff --git a/src/vppinfra/bihash_template.c b/src/vppinfra/bihash_template.c
index 752597ebbd5..e218f4b0dc6 100644
--- a/src/vppinfra/bihash_template.c
+++ b/src/vppinfra/bihash_template.c
@@ -203,7 +203,7 @@ void BV (clib_bihash_free) (BVT (clib_bihash) * h)
(void) close (h->memfd);
#endif
clib_mem_vm_free ((void *) (uword) (alloc_arena (h)), alloc_arena_size (h));
- memset (h, 0, sizeof (*h));
+ clib_memset (h, 0, sizeof (*h));
}
static
@@ -234,7 +234,7 @@ initialize:
* if we replace (1<<log2_pages) with vec_len(rv).
* No clue.
*/
- memset (rv, 0xff, sizeof (*rv) * (1 << log2_pages));
+ clib_memset (rv, 0xff, sizeof (*rv) * (1 << log2_pages));
return rv;
}
@@ -247,7 +247,7 @@ BV (value_free) (BVT (clib_bihash) * h, BVT (clib_bihash_value) * v,
ASSERT (vec_len (h->freelists) > log2_pages);
if (CLIB_DEBUG > 0)
- memset (v, 0xFE, sizeof (*v) * (1 << log2_pages));
+ clib_memset (v, 0xFE, sizeof (*v) * (1 << log2_pages));
v->next_free_as_u64 = (u64) h->freelists[log2_pages];
h->freelists[log2_pages] = (u64) BV (clib_bihash_get_offset) (h, v);
@@ -295,7 +295,7 @@ BV (make_working_copy) (BVT (clib_bihash) * h, BVT (clib_bihash_bucket) * b)
v = BV (clib_bihash_get_value) (h, b->offset);
- clib_memcpy (working_copy, v, sizeof (*v) * (1 << b->log2_pages));
+ _clib_memcpy (working_copy, v, sizeof (*v) * (1 << b->log2_pages));
working_bucket.as_u64 = b->as_u64;
working_bucket.offset = BV (clib_bihash_get_offset) (h, working_copy);
CLIB_MEMORY_BARRIER ();
@@ -338,8 +338,8 @@ BV (split_and_rehash)
/* Empty slot */
if (BV (clib_bihash_is_free) (&(new_v->kvp[j])))
{
- clib_memcpy (&(new_v->kvp[j]), &(old_values->kvp[i]),
- sizeof (new_v->kvp[j]));
+ _clib_memcpy (&(new_v->kvp[j]), &(old_values->kvp[i]),
+ sizeof (new_v->kvp[j]));
goto doublebreak;
}
}
@@ -383,8 +383,8 @@ BV (split_and_rehash_linear)
if (BV (clib_bihash_is_free) (&(new_values->kvp[j])))
{
/* Copy the old value and move along */
- clib_memcpy (&(new_values->kvp[j]), &(old_values->kvp[i]),
- sizeof (new_values->kvp[j]));
+ _clib_memcpy (&(new_values->kvp[j]), &(old_values->kvp[i]),
+ sizeof (new_values->kvp[j]));
j++;
goto doublebreak;
}
@@ -472,7 +472,7 @@ static inline int BV (clib_bihash_add_del_inline)
if (!memcmp (&(v->kvp[i]), &add_v->key, sizeof (add_v->key)))
{
CLIB_MEMORY_BARRIER (); /* Add a delay */
- clib_memcpy (&(v->kvp[i]), add_v, sizeof (*add_v));
+ _clib_memcpy (&(v->kvp[i]), add_v, sizeof (*add_v));
BV (clib_bihash_unlock_bucket) (b);
return (0);
}
@@ -488,10 +488,10 @@ static inline int BV (clib_bihash_add_del_inline)
* Copy the value first, so that if a reader manages
* to match the new key, the value will be right...
*/
- clib_memcpy (&(v->kvp[i].value),
- &add_v->value, sizeof (add_v->value));
+ _clib_memcpy (&(v->kvp[i].value),
+ &add_v->value, sizeof (add_v->value));
CLIB_MEMORY_BARRIER (); /* Make sure the value has settled */
- clib_memcpy (&(v->kvp[i]), &add_v->key, sizeof (add_v->key));
+ _clib_memcpy (&(v->kvp[i]), &add_v->key, sizeof (add_v->key));
b->refcnt++;
ASSERT (b->refcnt > 0);
BV (clib_bihash_unlock_bucket) (b);
@@ -506,7 +506,7 @@ static inline int BV (clib_bihash_add_del_inline)
if (is_stale_cb (&(v->kvp[i]), arg))
{
CLIB_MEMORY_BARRIER ();
- clib_memcpy (&(v->kvp[i]), add_v, sizeof (*add_v));
+ _clib_memcpy (&(v->kvp[i]), add_v, sizeof (*add_v));
BV (clib_bihash_unlock_bucket) (b);
return (0);
}
@@ -521,7 +521,7 @@ static inline int BV (clib_bihash_add_del_inline)
/* Found the key? Kill it... */
if (!memcmp (&(v->kvp[i]), &add_v->key, sizeof (add_v->key)))
{
- memset (&(v->kvp[i]), 0xff, sizeof (*(add_v)));
+ clib_memset (&(v->kvp[i]), 0xff, sizeof (*(add_v)));
/* Is the bucket empty? */
if (PREDICT_TRUE (b->refcnt > 1))
{
@@ -602,7 +602,7 @@ static inline int BV (clib_bihash_add_del_inline)
{
if (BV (clib_bihash_is_free) (&(new_v->kvp[i])))
{
- clib_memcpy (&(new_v->kvp[i]), add_v, sizeof (*add_v));
+ _clib_memcpy (&(new_v->kvp[i]), add_v, sizeof (*add_v));
goto expand_ok;
}
}
diff --git a/src/vppinfra/cuckoo_8_8.h b/src/vppinfra/cuckoo_8_8.h
index 6fe334da32d..a3d07c870eb 100644
--- a/src/vppinfra/cuckoo_8_8.h
+++ b/src/vppinfra/cuckoo_8_8.h
@@ -64,7 +64,7 @@ clib_cuckoo_kv_is_free_8_8 (const clib_cuckoo_kv_8_8_t * v)
always_inline void
clib_cuckoo_kv_set_free_8_8 (clib_cuckoo_kv_8_8_t * v)
{
- memset (v, 0xff, sizeof (*v));
+ clib_memset (v, 0xff, sizeof (*v));
}
/** Format a clib_cuckoo_kv_8_8_t instance
diff --git a/src/vppinfra/cuckoo_template.c b/src/vppinfra/cuckoo_template.c
index 595bd1ca3bc..119a407962f 100644
--- a/src/vppinfra/cuckoo_template.c
+++ b/src/vppinfra/cuckoo_template.c
@@ -180,7 +180,7 @@ void CV (clib_cuckoo_init) (CVT (clib_cuckoo) * h, const char *name,
CVT (clib_cuckoo_bucket) * bucket;
/* *INDENT-OFF* */
clib_cuckoo_foreach_bucket (
- bucket, h, { memset (bucket->elts, 0xff, sizeof (bucket->elts)); });
+ bucket, h, { clib_memset (bucket->elts, 0xff, sizeof (bucket->elts)); });
/* *INDENT-ON* */
h->name = name;
h->garbage_callback = garbage_callback;
@@ -189,7 +189,7 @@ void CV (clib_cuckoo_init) (CVT (clib_cuckoo) * h, const char *name,
void CV (clib_cuckoo_free) (CVT (clib_cuckoo) * h)
{
- memset (h, 0, sizeof (*h));
+ clib_memset (h, 0, sizeof (*h));
}
static clib_cuckoo_bucket_aux_t
@@ -227,7 +227,7 @@ static clib_cuckoo_path_t *CV (clib_cuckoo_path_get) (CVT (clib_cuckoo) * h)
{
clib_cuckoo_path_t *path;
pool_get (h->paths, path);
- memset (path, 0, sizeof (*path));
+ clib_memset (path, 0, sizeof (*path));
#if CLIB_CUCKOO_DEBUG_PATH_DETAIL
CLIB_CUCKOO_DBG ("Get path @%lu", (long unsigned) (path - h->paths));
#endif
@@ -531,10 +531,10 @@ static void CV (clib_cuckoo_bucket_tidy) (CVT (clib_cuckoo_bucket) * b)
static void CV (clib_cuckoo_free_locked_elt) (CVT (clib_cuckoo_kv) * elt)
{
/*
- * FIXME - improve performance by getting rid of this memset - make all
+ * FIXME - improve performance by getting rid of this clib_memset - make all
* functions in this file not rely on clib_cuckoo_kv_is_free but instead
* take use_count into account */
- memset (elt, 0xff, sizeof (*elt));
+ clib_memset (elt, 0xff, sizeof (*elt));
}
static void CV (clib_cuckoo_free_elt_in_bucket) (CVT (clib_cuckoo_bucket) * b,
@@ -736,7 +736,7 @@ static void CV (clib_cuckoo_rehash) (CVT (clib_cuckoo) * h)
CVT (clib_cuckoo_bucket) * bucket;
for (bucket = new + old_nbuckets; bucket < vec_end (new); ++bucket)
{
- memset (bucket->elts, 0xff, sizeof (bucket->elts));
+ clib_memset (bucket->elts, 0xff, sizeof (bucket->elts));
}
/*
* this for loop manipulates the new (unseen) memory, so no locks
diff --git a/src/vppinfra/dlist.h b/src/vppinfra/dlist.h
index e445b39f336..d28500dc49f 100644
--- a/src/vppinfra/dlist.h
+++ b/src/vppinfra/dlist.h
@@ -36,7 +36,7 @@ static inline void
clib_dlist_init (dlist_elt_t * pool, u32 index)
{
dlist_elt_t *head = pool_elt_at_index (pool, index);
- memset (head, 0xFF, sizeof (*head));
+ clib_memset (head, 0xFF, sizeof (*head));
}
static inline void
diff --git a/src/vppinfra/elf.c b/src/vppinfra/elf.c
index 931fbcccc48..a8c5d307cdf 100644
--- a/src/vppinfra/elf.c
+++ b/src/vppinfra/elf.c
@@ -983,7 +983,7 @@ elf_parse (elf_main_t * em, void *data, uword data_bytes)
{
char *save = em->file_name;
- memset (em, 0, sizeof (em[0]));
+ clib_memset (em, 0, sizeof (em[0]));
em->file_name = save;
}
@@ -1435,7 +1435,7 @@ static void string_table_init (string_table_builder_t * b, u8 * old_table)
static void
string_table_init (string_table_builder_t * b, u8 * old_table)
{
- memset (b, 0, sizeof (b[0]));
+ clib_memset (b, 0, sizeof (b[0]));
b->old_table = old_table;
b->hash = hash_create_string (0, sizeof (uword));
}
diff --git a/src/vppinfra/elf.h b/src/vppinfra/elf.h
index c57b06f5d2a..cceb13e256b 100644
--- a/src/vppinfra/elf.h
+++ b/src/vppinfra/elf.h
@@ -919,7 +919,7 @@ typedef struct
always_inline void
elf_main_init (elf_main_t * em)
{
- memset (em, 0, sizeof (em[0]));
+ clib_memset (em, 0, sizeof (em[0]));
}
always_inline void
diff --git a/src/vppinfra/elog.c b/src/vppinfra/elog.c
index c6902eb86ea..8e3f6c18dfa 100644
--- a/src/vppinfra/elog.c
+++ b/src/vppinfra/elog.c
@@ -469,7 +469,7 @@ elog_alloc (elog_main_t * em, u32 n_events)
void
elog_init (elog_main_t * em, u32 n_events)
{
- memset (em, 0, sizeof (em[0]));
+ clib_memset (em, 0, sizeof (em[0]));
em->lock = 0;
@@ -636,7 +636,7 @@ elog_merge (elog_main_t * dst, u8 * dst_tag, elog_main_t * src, u8 * src_tag,
elog_track_t newt;
int i;
- memset (&newt, 0, sizeof (newt));
+ clib_memset (&newt, 0, sizeof (newt));
/* Acquire src and dst events */
elog_get_events (src);
diff --git a/src/vppinfra/fheap.c b/src/vppinfra/fheap.c
index 1369245615a..034168e85ab 100644
--- a/src/vppinfra/fheap.c
+++ b/src/vppinfra/fheap.c
@@ -167,7 +167,7 @@ fheap_add (fheap_t * f, u32 ni, u32 key)
n = vec_elt_at_index (f->nodes, ni);
- memset (n, 0, sizeof (n[0]));
+ clib_memset (n, 0, sizeof (n[0]));
n->parent = n->first_child = n->next_sibling = n->prev_sibling = ~0;
n->key = key;
diff --git a/src/vppinfra/fheap.h b/src/vppinfra/fheap.h
index 6d4965f1bea..1dbd52bad76 100644
--- a/src/vppinfra/fheap.h
+++ b/src/vppinfra/fheap.h
@@ -89,7 +89,7 @@ fheap_init (fheap_t * f, u32 n_nodes)
fheap_node_t *save_nodes = f->nodes;
u32 *save_root_list = f->root_list_by_rank;
- memset (f, 0, sizeof (f[0]));
+ clib_memset (f, 0, sizeof (f[0]));
f->nodes = save_nodes;
f->root_list_by_rank = save_root_list;
diff --git a/src/vppinfra/fifo.c b/src/vppinfra/fifo.c
index 5b4c76d1084..e3b7b415cb3 100644
--- a/src/vppinfra/fifo.c
+++ b/src/vppinfra/fifo.c
@@ -121,7 +121,7 @@ _clib_fifo_resize (void *v_old, uword n_new_elts, uword elt_bytes)
/* Zero empty space. */
n_zero_bytes = (n_new_elts - n_old_elts) * elt_bytes;
- memset (v_new + n_copy_bytes, 0, n_zero_bytes);
+ clib_memset (v_new + n_copy_bytes, 0, n_zero_bytes);
clib_fifo_free (v_old);
diff --git a/src/vppinfra/flowhash_template.h b/src/vppinfra/flowhash_template.h
index 92272563878..d7a621c1754 100644
--- a/src/vppinfra/flowhash_template.h
+++ b/src/vppinfra/flowhash_template.h
@@ -374,7 +374,7 @@ FVT(flowhash) *FV(flowhash_alloc)(u32 fixed_entries, u32 collision_buckets)
/* Fill free elements list */
int i;
- memset(h->entries, 0, sizeof(h->entries[0]) * entries);
+ clib_memset(h->entries, 0, sizeof(h->entries[0]) * entries);
for (i = 1; i <= collision_buckets; i++)
{
h->free_buckets_indices[-i] =
diff --git a/src/vppinfra/format.c b/src/vppinfra/format.c
index e2fd84bb08b..886f03d9c5f 100644
--- a/src/vppinfra/format.c
+++ b/src/vppinfra/format.c
@@ -139,13 +139,13 @@ justify (u8 * s, format_info_t * fi, uword s_len_orig)
if (n_left > 0)
{
vec_insert (s, n_left, i0);
- memset (s + i0, fi->pad_char, n_left);
+ clib_memset (s + i0, fi->pad_char, n_left);
l1 = vec_len (s);
}
if (n_right > 0)
{
vec_resize (s, n_right);
- memset (s + l1, fi->pad_char, n_right);
+ clib_memset (s + l1, fi->pad_char, n_right);
}
}
return s;
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h
index 9a3a342076b..94344474067 100644
--- a/src/vppinfra/format.h
+++ b/src/vppinfra/format.h
@@ -153,7 +153,7 @@ unformat_init (unformat_input_t * i,
uword (*fill_buffer) (unformat_input_t *),
void *fill_buffer_arg)
{
- memset (i, 0, sizeof (i[0]));
+ clib_memset (i, 0, sizeof (i[0]));
i->fill_buffer = fill_buffer;
i->fill_buffer_arg = fill_buffer_arg;
}
@@ -163,7 +163,7 @@ unformat_free (unformat_input_t * i)
{
vec_free (i->buffer);
vec_free (i->buffer_marks);
- memset (i, 0, sizeof (i[0]));
+ clib_memset (i, 0, sizeof (i[0]));
}
always_inline uword
diff --git a/src/vppinfra/graph.c b/src/vppinfra/graph.c
index ea11a96f1c8..3f8a3e8423e 100644
--- a/src/vppinfra/graph.c
+++ b/src/vppinfra/graph.c
@@ -102,7 +102,7 @@ graph_del_node (graph_t * g, u32 src)
index = src_node - g->nodes;
pool_put (g->nodes, src_node);
- memset (src_node, ~0, sizeof (src_node[0]));
+ clib_memset (src_node, ~0, sizeof (src_node[0]));
return index;
}
diff --git a/src/vppinfra/hash.c b/src/vppinfra/hash.c
index abc7c4ce4a2..2ff8ebfd17b 100644
--- a/src/vppinfra/hash.c
+++ b/src/vppinfra/hash.c
@@ -43,13 +43,13 @@
always_inline void
zero_pair (hash_t * h, hash_pair_t * p)
{
- memset (p, 0, hash_pair_bytes (h));
+ clib_memset (p, 0, hash_pair_bytes (h));
}
always_inline void
init_pair (hash_t * h, hash_pair_t * p)
{
- memset (p->value, ~0, hash_value_bytes (h));
+ clib_memset (p->value, ~0, hash_value_bytes (h));
}
always_inline hash_pair_union_t *
@@ -624,7 +624,7 @@ hash_next (void *v, hash_next_t * hn)
{
/* Restore flags. */
h->flags = hn->f;
- memset (hn, 0, sizeof (hn[0]));
+ clib_memset (hn, 0, sizeof (hn[0]));
return 0;
}
diff --git a/src/vppinfra/hash.h b/src/vppinfra/hash.h
index 36a70066044..892b2ea916c 100644
--- a/src/vppinfra/hash.h
+++ b/src/vppinfra/hash.h
@@ -496,7 +496,7 @@ hash_set_value_bytes (hash_t * h, uword value_bytes)
_format_pair,_format_pair_arg) \
({ \
hash_t _h; \
- memset (&_h, 0, sizeof (_h)); \
+ clib_memset (&_h, 0, sizeof (_h)); \
_h.user = (_user); \
_h.key_sum = (hash_key_sum_function_t *) (_key_sum); \
_h.key_equal = (_key_equal); \
diff --git a/src/vppinfra/heap.c b/src/vppinfra/heap.c
index 2a5fb5c8d8e..f7b1f6bb31e 100644
--- a/src/vppinfra/heap.c
+++ b/src/vppinfra/heap.c
@@ -698,7 +698,7 @@ format_heap (u8 * s, va_list * va)
heap_header_t *h = heap_header (v);
heap_header_t zero;
- memset (&zero, 0, sizeof (zero));
+ clib_memset (&zero, 0, sizeof (zero));
if (!v)
h = &zero;
diff --git a/src/vppinfra/heap.h b/src/vppinfra/heap.h
index f76c9453e65..b6e9f022852 100644
--- a/src/vppinfra/heap.h
+++ b/src/vppinfra/heap.h
@@ -260,7 +260,7 @@ heap_create_from_memory (void *memory, uword max_len, uword elt_bytes)
return 0;
h = memory;
- memset (h, 0, sizeof (h[0]));
+ clib_memset (h, 0, sizeof (h[0]));
h->max_len = max_len;
h->elt_bytes = elt_bytes;
h->flags = HEAP_IS_STATIC;
diff --git a/src/vppinfra/lock.h b/src/vppinfra/lock.h
index 4645378360d..337c5a3f0ad 100644
--- a/src/vppinfra/lock.h
+++ b/src/vppinfra/lock.h
@@ -57,7 +57,7 @@ static inline void
clib_spinlock_init (clib_spinlock_t * p)
{
*p = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);
- memset ((void *) *p, 0, CLIB_CACHE_LINE_BYTES);
+ clib_memset ((void *) *p, 0, CLIB_CACHE_LINE_BYTES);
}
static inline void
@@ -122,7 +122,7 @@ always_inline void
clib_rwlock_init (clib_rwlock_t * p)
{
*p = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);
- memset ((void *) *p, 0, CLIB_CACHE_LINE_BYTES);
+ clib_memset ((void *) *p, 0, CLIB_CACHE_LINE_BYTES);
}
always_inline void
diff --git a/src/vppinfra/maplog.c b/src/vppinfra/maplog.c
index 1900aa8f03b..68913365130 100644
--- a/src/vppinfra/maplog.c
+++ b/src/vppinfra/maplog.c
@@ -42,7 +42,7 @@ clib_maplog_init (clib_maplog_init_args_t * a)
if (mm->flags & CLIB_MAPLOG_FLAG_INIT)
return (-2);
- memset (mm, 0, sizeof (*mm));
+ clib_memset (mm, 0, sizeof (*mm));
record_size_in_cache_lines =
(a->record_size_in_bytes + CLIB_CACHE_LINE_BYTES -
@@ -113,7 +113,7 @@ clib_maplog_init (clib_maplog_init_args_t * a)
(void) close (fd);
}
- memset (h, 0, sizeof (*h));
+ clib_memset (h, 0, sizeof (*h));
h->maplog_major_version = MAPLOG_MAJOR_VERSION;
h->maplog_minor_version = MAPLOG_MINOR_VERSION;
h->maplog_patch_version = MAPLOG_PATCH_VERSION;
@@ -321,7 +321,7 @@ clib_maplog_close (clib_maplog_main_t * mm)
vec_free (mm->file_basename);
vec_free (mm->header_filename);
- memset (mm, 0, sizeof (*mm));
+ clib_memset (mm, 0, sizeof (*mm));
}
/**
diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h
index 9cc62ed7592..04c26d218aa 100644
--- a/src/vppinfra/mem.h
+++ b/src/vppinfra/mem.h
@@ -52,7 +52,7 @@
#endif
#include <vppinfra/os.h>
-#include <vppinfra/string.h> /* memcpy, memset */
+#include <vppinfra/string.h> /* memcpy, clib_memset */
#include <vppinfra/valgrind.h>
#define CLIB_MAX_MHEAPS 256
diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c
index 8afb0507092..6268709bb36 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -73,7 +73,7 @@ mheap_get_trace (uword offset, uword size)
return;
/* Spurious Coverity warnings be gone. */
- memset (&trace, 0, sizeof (trace));
+ clib_memset (&trace, 0, sizeof (trace));
/* Skip our frame and mspace_get_aligned's frame */
n_callers = clib_backtrace (trace.callers, ARRAY_LEN (trace.callers), 2);
@@ -185,7 +185,7 @@ mheap_put_trace (uword offset, uword size)
{
hash_unset_mem (tm->trace_by_callers, t->callers);
vec_add1 (tm->trace_free_list, trace_index);
- memset (t, 0, sizeof (t[0]));
+ clib_memset (t, 0, sizeof (t[0]));
}
tm->enabled = save_enabled;
clib_spinlock_unlock (&tm->lock);
diff --git a/src/vppinfra/memcpy_avx2.h b/src/vppinfra/memcpy_avx2.h
index 6519d86924e..64dff4e5ddb 100644
--- a/src/vppinfra/memcpy_avx2.h
+++ b/src/vppinfra/memcpy_avx2.h
@@ -109,7 +109,7 @@ clib_mov128blocks (u8 * dst, const u8 * src, size_t n)
}
static inline void *
-clib_memcpy (void *dst, const void *src, size_t n)
+_clib_memcpy (void *dst, const void *src, size_t n)
{
uword dstu = (uword) dst;
uword srcu = (uword) src;
diff --git a/src/vppinfra/memcpy_avx512.h b/src/vppinfra/memcpy_avx512.h
index 67982500b6c..e5245268770 100644
--- a/src/vppinfra/memcpy_avx512.h
+++ b/src/vppinfra/memcpy_avx512.h
@@ -139,7 +139,7 @@ clib_mov512blocks (u8 * dst, const u8 * src, size_t n)
}
static inline void *
-clib_memcpy (void *dst, const void *src, size_t n)
+_clib_memcpy (void *dst, const void *src, size_t n)
{
uword dstu = (uword) dst;
uword srcu = (uword) src;
diff --git a/src/vppinfra/memcpy_sse3.h b/src/vppinfra/memcpy_sse3.h
index 5e4bf7d79c5..2dd9399d428 100644
--- a/src/vppinfra/memcpy_sse3.h
+++ b/src/vppinfra/memcpy_sse3.h
@@ -183,7 +183,7 @@ clib_mov256 (u8 * dst, const u8 * src)
})
static inline void *
-clib_memcpy (void *dst, const void *src, size_t n)
+_clib_memcpy (void *dst, const void *src, size_t n)
{
__m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8;
uword dstu = (uword) dst;
diff --git a/src/vppinfra/mhash.c b/src/vppinfra/mhash.c
index b694cc7c50f..e09d7193f68 100644
--- a/src/vppinfra/mhash.c
+++ b/src/vppinfra/mhash.c
@@ -202,7 +202,7 @@ mhash_init (mhash_t * h, uword n_value_bytes, uword n_key_bytes)
vec_free (h->key_tmps);
hash_free (h->hash);
- memset (h, 0, sizeof (h[0]));
+ clib_memset (h, 0, sizeof (h[0]));
h->n_key_bytes = n_key_bytes;
#if 0
diff --git a/src/vppinfra/mheap.c b/src/vppinfra/mheap.c
index 0a62943e2f2..ba5bbc9b6e7 100644
--- a/src/vppinfra/mheap.c
+++ b/src/vppinfra/mheap.c
@@ -935,7 +935,7 @@ mheap_alloc_with_flags (void *memory, uword memory_size, uword flags)
clib_mem_vm_map (h, sizeof (h[0]));
/* Zero vector header: both heap header and vector length. */
- memset (h, 0, sizeof (h[0]));
+ clib_memset (h, 0, sizeof (h[0]));
_vec_len (v) = 0;
h->vm_alloc_offset_from_header = (void *) h - memory;
@@ -953,8 +953,8 @@ mheap_alloc_with_flags (void *memory, uword memory_size, uword flags)
(clib_address_t) v, h->max_size);
/* Initialize free list heads to empty. */
- memset (h->first_free_elt_uoffset_by_bin, 0xFF,
- sizeof (h->first_free_elt_uoffset_by_bin));
+ clib_memset (h->first_free_elt_uoffset_by_bin, 0xFF,
+ sizeof (h->first_free_elt_uoffset_by_bin));
return v;
}
@@ -1236,7 +1236,7 @@ format_mheap (u8 * s, va_list * va)
mheap_elt_t *e;
uword i, n_hist;
- memset (hist, 0, sizeof (hist));
+ clib_memset (hist, 0, sizeof (hist));
n_hist = 0;
for (e = v;
@@ -1536,7 +1536,7 @@ mheap_get_trace (void *v, uword offset, uword size)
mheap_trace_t trace;
/* Spurious Coverity warnings be gone. */
- memset (&trace, 0, sizeof (trace));
+ clib_memset (&trace, 0, sizeof (trace));
n_callers = clib_backtrace (trace.callers, ARRAY_LEN (trace.callers),
/* Skip mheap_get_aligned's frame */ 1);
@@ -1630,7 +1630,7 @@ mheap_put_trace (void *v, uword offset, uword size)
{
hash_unset_mem (tm->trace_by_callers, t->callers);
vec_add1 (tm->trace_free_list, trace_index);
- memset (t, 0, sizeof (t[0]));
+ clib_memset (t, 0, sizeof (t[0]));
}
}
diff --git a/src/vppinfra/phash.c b/src/vppinfra/phash.c
index f6eecaa4103..52c29b33f78 100644
--- a/src/vppinfra/phash.c
+++ b/src/vppinfra/phash.c
@@ -605,7 +605,7 @@ perfect (phash_main_t * pm)
/* clear any state from previous attempts */
if (vec_bytes (pm->tabh))
- memset (pm->tabh, ~0, vec_bytes (pm->tabh));
+ clib_memset (pm->tabh, ~0, vec_bytes (pm->tabh));
vec_validate (pm->tabb_sort, vec_len (pm->tabb) - 1);
for (i = 0; i < vec_len (pm->tabb_sort); i++)
diff --git a/src/vppinfra/phash.h b/src/vppinfra/phash.h
index 746a0fddfab..3dc59c724f7 100644
--- a/src/vppinfra/phash.h
+++ b/src/vppinfra/phash.h
@@ -168,7 +168,7 @@ phash_main_free (phash_main_t * pm)
phash_main_free_working_memory (pm);
vec_free (pm->tab);
vec_free (pm->keys);
- memset (pm, 0, sizeof (pm[0]));
+ clib_memset (pm, 0, sizeof (pm[0]));
}
/* Slow hash computation for general keys. */
diff --git a/src/vppinfra/pool.c b/src/vppinfra/pool.c
index ed83b41afef..ed04eb68e31 100644
--- a/src/vppinfra/pool.c
+++ b/src/vppinfra/pool.c
@@ -107,7 +107,8 @@ _pool_init_fixed (void **pool_ptr, u32 elt_size, u32 max_elts)
/* Set the entire free bitmap */
clib_bitmap_alloc (fh->free_bitmap, max_elts);
- memset (fh->free_bitmap, 0xff, vec_len (fh->free_bitmap) * sizeof (uword));
+ clib_memset (fh->free_bitmap, 0xff,
+ vec_len (fh->free_bitmap) * sizeof (uword));
/* Clear any extraneous set bits */
set_bits = vec_len (fh->free_bitmap) * BITS (uword);
diff --git a/src/vppinfra/qhash.c b/src/vppinfra/qhash.c
index f4e38c4a1d7..3b5a175065d 100644
--- a/src/vppinfra/qhash.c
+++ b/src/vppinfra/qhash.c
@@ -61,7 +61,7 @@ _qhash_resize (void *v, uword length, uword elt_bytes)
CLIB_CACHE_LINE_BYTES);
vec_resize (h->hash_key_valid_bitmap,
1 << (l - QHASH_LOG2_KEYS_PER_BUCKET));
- memset (v, ~0, elt_bytes << l);
+ clib_memset (v, ~0, elt_bytes << l);
return v;
}
@@ -123,7 +123,8 @@ qhash_get_multiple (void *v,
if (!v)
{
- memset (result_indices, ~0, sizeof (result_indices[0]) * n_search_keys);
+ clib_memset (result_indices, ~0,
+ sizeof (result_indices[0]) * n_search_keys);
return;
}
@@ -417,7 +418,7 @@ qhash_set_overflow (void *v, uword elt_bytes,
uword dl = round_pow2 (1 + i - l, 8);
v = _vec_resize (v, dl, (l + dl) * elt_bytes, sizeof (h[0]),
/* align */ sizeof (uword));
- memset (v + l * elt_bytes, ~0, dl * elt_bytes);
+ clib_memset (v + l * elt_bytes, ~0, dl * elt_bytes);
}
}
diff --git a/src/vppinfra/random_buffer.c b/src/vppinfra/random_buffer.c
index df03698066c..52de5d34dd0 100644
--- a/src/vppinfra/random_buffer.c
+++ b/src/vppinfra/random_buffer.c
@@ -63,7 +63,7 @@ clib_random_buffer_init (clib_random_buffer_t * b, uword seed)
{
uword i, j;
- memset (b, 0, sizeof (b[0]));
+ clib_memset (b, 0, sizeof (b[0]));
/* Seed ISAAC. */
for (i = 0; i < ARRAY_LEN (b->ctx); i++)
diff --git a/src/vppinfra/serialize.c b/src/vppinfra/serialize.c
index a098aa2d98a..ef9cf03f362 100644
--- a/src/vppinfra/serialize.c
+++ b/src/vppinfra/serialize.c
@@ -572,7 +572,7 @@ unserialize_heap (serialize_main_t * m, va_list * va)
return;
}
- memset (&h, 0, sizeof (h));
+ clib_memset (&h, 0, sizeof (h));
#define _(f) unserialize_integer (m, &h.f, sizeof (h.f));
foreach_serialize_heap_header_integer;
#undef _
@@ -882,7 +882,7 @@ unserialize_close (serialize_main_t * m)
void
serialize_open_data (serialize_main_t * m, u8 * data, uword n_data_bytes)
{
- memset (m, 0, sizeof (m[0]));
+ clib_memset (m, 0, sizeof (m[0]));
m->stream.buffer = data;
m->stream.n_buffer_bytes = n_data_bytes;
}
@@ -908,7 +908,7 @@ serialize_vector_write (serialize_main_header_t * m, serialize_stream_t * s)
void
serialize_open_vector (serialize_main_t * m, u8 * vector)
{
- memset (m, 0, sizeof (m[0]));
+ clib_memset (m, 0, sizeof (m[0]));
m->header.data_function = serialize_vector_write;
m->stream.buffer = vector;
m->stream.current_buffer_index = 0;
@@ -926,7 +926,7 @@ serialize_close_vector (serialize_main_t * m)
if (s->buffer)
_vec_len (s->buffer) = s->current_buffer_index;
result = s->buffer;
- memset (m, 0, sizeof (m[0]));
+ clib_memset (m, 0, sizeof (m[0]));
return result;
}
@@ -1192,7 +1192,7 @@ static void
serialize_open_clib_file_descriptor_helper (serialize_main_t * m, int fd,
uword is_read)
{
- memset (m, 0, sizeof (m[0]));
+ clib_memset (m, 0, sizeof (m[0]));
vec_resize (m->stream.buffer, 4096);
if (!is_read)
diff --git a/src/vppinfra/slist.c b/src/vppinfra/slist.c
index 892517bbb79..5598871c884 100644
--- a/src/vppinfra/slist.c
+++ b/src/vppinfra/slist.c
@@ -54,7 +54,7 @@ clib_slist_init (clib_slist_t * sp, f64 branching_factor,
format_function_t format_user_element)
{
clib_slist_elt_t *head;
- memset (sp, 0, sizeof (sp[0]));
+ clib_memset (sp, 0, sizeof (sp[0]));
sp->branching_factor = branching_factor;
sp->format_user_element = format_user_element;
sp->compare = compare;
@@ -88,7 +88,7 @@ slist_search_internal (clib_slist_t * sp, void *key, int need_full_path)
* Initial negotiating position, only the head_elt is
* lighter than the supplied key
*/
- memset (sp->path, 0, vec_len (head_elt->n.nexts) * sizeof (u32));
+ clib_memset (sp->path, 0, vec_len (head_elt->n.nexts) * sizeof (u32));
/* Walk the fastest lane first */
level = vec_len (head_elt->n.nexts) - 1;
diff --git a/src/vppinfra/socket.c b/src/vppinfra/socket.c
index 29b2a945cb9..990d0f7390b 100644
--- a/src/vppinfra/socket.c
+++ b/src/vppinfra/socket.c
@@ -73,7 +73,7 @@ find_free_port (word sock)
{
struct sockaddr_in a;
- memset (&a, 0, sizeof (a)); /* Warnings be gone */
+ clib_memset (&a, 0, sizeof (a)); /* Warnings be gone */
a.sin_family = PF_INET;
a.sin_addr.s_addr = INADDR_ANY;
@@ -289,7 +289,7 @@ default_socket_sendmsg (clib_socket_t * s, void *msg, int msglen,
if (num_fds > 0)
{
struct cmsghdr *cmsg;
- memset (&ctl, 0, sizeof (ctl));
+ clib_memset (&ctl, 0, sizeof (ctl));
mh.msg_control = ctl;
mh.msg_controllen = sizeof (ctl);
cmsg = CMSG_FIRSTHDR (&mh);
@@ -328,7 +328,7 @@ default_socket_recvmsg (clib_socket_t * s, void *msg, int msglen,
mh.msg_control = ctl;
mh.msg_controllen = sizeof (ctl);
- memset (ctl, 0, sizeof (ctl));
+ clib_memset (ctl, 0, sizeof (ctl));
/* receive the incoming message */
size = recvmsg (s->fd, &mh, 0);
@@ -525,7 +525,7 @@ clib_socket_accept (clib_socket_t * server, clib_socket_t * client)
clib_error_t *err = 0;
socklen_t len = 0;
- memset (client, 0, sizeof (client[0]));
+ clib_memset (client, 0, sizeof (client[0]));
/* Accept the new socket connection. */
client->fd = accept (server->fd, 0, 0);
diff --git a/src/vppinfra/socket.h b/src/vppinfra/socket.h
index 4f9e9509342..b5f005839e4 100644
--- a/src/vppinfra/socket.h
+++ b/src/vppinfra/socket.h
@@ -168,7 +168,7 @@ clib_socket_free (clib_socket_t * s)
vec_free (s->rx_buffer);
if (clib_mem_is_heap_object (s->config))
vec_free (s->config);
- memset (s, 0, sizeof (s[0]));
+ clib_memset (s, 0, sizeof (s[0]));
}
always_inline clib_error_t *
diff --git a/src/vppinfra/string.c b/src/vppinfra/string.c
index ba21e7b3490..b90f432c0cc 100644
--- a/src/vppinfra/string.c
+++ b/src/vppinfra/string.c
@@ -85,6 +85,25 @@ clib_memswap (void *_a, void *_b, uword bytes)
}
}
+void
+clib_c11_violation (const char *s)
+{
+ _clib_error (CLIB_ERROR_WARNING, (char *) __FUNCTION__, 0, (char *) s);
+}
+
+errno_t
+memcpy_s (void *__restrict__ dest, rsize_t dmax,
+ const void *__restrict__ src, rsize_t n)
+{
+ return memcpy_s_inline (dest, dmax, src, n);
+}
+
+errno_t
+memset_s (void *s, rsize_t smax, int c, rsize_t n)
+{
+ return memset_s_inline (s, smax, c, n);
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vppinfra/string.h b/src/vppinfra/string.h
index 2c794baf71f..5c1d8267742 100644
--- a/src/vppinfra/string.h
+++ b/src/vppinfra/string.h
@@ -35,6 +35,12 @@
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+/** \file
+
+ Optimized string handling code, including c11-compliant
+ "safe C library" variants.
+*/
+
#ifndef included_clib_string_h
#define included_clib_string_h
@@ -72,12 +78,114 @@ void clib_memswap (void *_a, void *_b, uword bytes);
#elif __SSSE3__
#include <vppinfra/memcpy_sse3.h>
#else
-#define clib_memcpy(a,b,c) memcpy(a,b,c)
+#define _clib_memcpy(a,b,c) memcpy(a,b,c)
#endif
#else /* __COVERITY__ */
-#define clib_memcpy(a,b,c) memcpy(a,b,c)
+#define _clib_memcpy(a,b,c) memcpy(a,b,c)
#endif
+/* c-11 string manipulation variants */
+
+#ifndef EOK
+#define EOK 0
+#endif
+#ifndef EINVAL
+#define EINVAL 22
+#endif
+
+typedef int errno_t;
+typedef uword rsize_t;
+
+void clib_c11_violation (const char *s);
+errno_t memcpy_s (void *__restrict__ dest, rsize_t dmax,
+ const void *__restrict__ src, rsize_t n);
+
+always_inline errno_t
+memcpy_s_inline (void *__restrict__ dest, rsize_t dmax,
+ const void *__restrict__ src, rsize_t n)
+{
+ uword low, hi;
+ u8 bad;
+
+ /*
+ * call bogus if: src or dst NULL, trying to copy
+ * more data than we have space in dst, or src == dst.
+ * n == 0 isn't really "bad", so check first in the
+ * "wall-of-shame" department...
+ */
+ bad = (dest == 0) + (src == 0) + (n > dmax) + (dest == src) + (n == 0);
+ if (PREDICT_FALSE (bad != 0))
+ {
+ /* Not actually trying to copy anything is OK */
+ if (n == 0)
+ return EOK;
+ if (dest == NULL)
+ clib_c11_violation ("dest NULL");
+ if (src == NULL)
+ clib_c11_violation ("src NULL");
+ if (n > dmax)
+ clib_c11_violation ("n > dmax");
+ if (dest == src)
+ clib_c11_violation ("dest == src");
+ return EINVAL;
+ }
+
+ /* Check for src/dst overlap, which is not allowed */
+ low = (uword) (src < dest ? src : dest);
+ hi = (uword) (src < dest ? dest : src);
+
+ if (PREDICT_FALSE (low + (n - 1) >= hi))
+ {
+ clib_c11_violation ("src/dest overlap");
+ return EINVAL;
+ }
+
+ _clib_memcpy (dest, src, n);
+ return EOK;
+}
+
+/*
+ * Note: $$$ This macro is a crutch. Folks need to manually
+ * inspect every extant clib_memcpy(...) call and
+ * attempt to provide a real destination buffer size
+ * argument...
+ */
+#define clib_memcpy(d,s,n) memcpy_s_inline(d,n,s,n)
+
+errno_t memset_s (void *s, rsize_t smax, int c, rsize_t n);
+
+always_inline errno_t
+memset_s_inline (void *s, rsize_t smax, int c, rsize_t n)
+{
+ u8 bad;
+
+ bad = (s == 0) + (n > smax);
+
+ if (PREDICT_FALSE (bad != 0))
+ {
+ if (s == 0)
+ clib_c11_violation ("s NULL");
+ if (n > smax)
+ clib_c11_violation ("n > smax");
+ return (EINVAL);
+ }
+ memset (s, c, n);
+ return (EOK);
+}
+
+/*
+ * This macro is not [so much of] a crutch.
+ * It's super-typical to write:
+ *
+ * ep = pool_get (<pool>);
+ * clib_memset(ep, 0, sizeof (*ep));
+ *
+ * The compiler should delete the not-so useful
+ * (n > smax) test. TBH the NULL pointer check isn't
+ * so useful in this case, but so be it.
+ */
+#define clib_memset(s,c,n) memset_s_inline(s,n,c,n)
+
/*
* Copy 64 bytes of data to 4 destinations
* this function is typically used in quad-loop case when whole cacheline
@@ -575,7 +683,6 @@ clib_count_equal_u8 (u8 * data, uword max_count)
return count;
}
-
#endif /* included_clib_string_h */
/*
diff --git a/src/vppinfra/test_cuckoo_bihash.c b/src/vppinfra/test_cuckoo_bihash.c
index eb17eed2ba1..3e63f0bee01 100644
--- a/src/vppinfra/test_cuckoo_bihash.c
+++ b/src/vppinfra/test_cuckoo_bihash.c
@@ -413,7 +413,7 @@ main (int argc, char *argv[])
unformat_input_t i;
clib_error_t *error;
test_main_t *tm = &test_main;
- memset (&test_main, 0, sizeof (test_main));
+ clib_memset (&test_main, 0, sizeof (test_main));
clib_mem_init (0, 3ULL << 30);
diff --git a/src/vppinfra/test_elf.c b/src/vppinfra/test_elf.c
index 84fe0776c33..3bed95484f7 100644
--- a/src/vppinfra/test_elf.c
+++ b/src/vppinfra/test_elf.c
@@ -72,7 +72,7 @@ elf_set_interpreter (elf_main_t * em, char *interp)
return error;
/* Put in new null terminated string. */
- memset (s->contents, 0, vec_len (s->contents));
+ clib_memset (s->contents, 0, vec_len (s->contents));
clib_memcpy (s->contents, interp, strlen (interp));
return 0;
@@ -146,7 +146,7 @@ main (int argc, char *argv[])
unformat_input_t i;
clib_error_t *error = 0;
- memset (tm, 0, sizeof (tm[0]));
+ clib_memset (tm, 0, sizeof (tm[0]));
unformat_init_command_line (&i, argv);
while (unformat_check_input (&i) != UNFORMAT_END_OF_INPUT)
diff --git a/src/vppinfra/test_heap.c b/src/vppinfra/test_heap.c
index 54a1f09710d..0fd6bf74245 100644
--- a/src/vppinfra/test_heap.c
+++ b/src/vppinfra/test_heap.c
@@ -95,7 +95,7 @@ main (int argc, char *argv[])
vec_resize (objects, 1000);
if (vec_bytes (objects) > 0) /* stupid warning be gone */
- memset (objects, ~0, vec_bytes (objects));
+ clib_memset (objects, ~0, vec_bytes (objects));
vec_resize (handles, vec_len (objects));
objects_used = 0;
diff --git a/src/vppinfra/test_maplog.c b/src/vppinfra/test_maplog.c
index f3ff6623a3e..b51f7f51b25 100644
--- a/src/vppinfra/test_maplog.c
+++ b/src/vppinfra/test_maplog.c
@@ -79,7 +79,7 @@ test_maplog_main (unformat_input_t * input)
clib_warning ("unknown input '%U'", format_unformat_error, input);
}
- memset (a, 0, sizeof (*a));
+ clib_memset (a, 0, sizeof (*a));
a->mm = mm;
a->file_basename = "/tmp/maplog_test";
a->file_size_in_bytes = 4096;
@@ -107,7 +107,7 @@ test_maplog_main (unformat_input_t * input)
}
if (noclose)
- memset (mm, 0, sizeof (*mm));
+ clib_memset (mm, 0, sizeof (*mm));
else
clib_maplog_close (mm);
diff --git a/src/vppinfra/test_mheap.c b/src/vppinfra/test_mheap.c
index f6923a96926..de94065edaf 100644
--- a/src/vppinfra/test_mheap.c
+++ b/src/vppinfra/test_mheap.c
@@ -154,7 +154,7 @@ test_mheap_main (unformat_input_t * input)
vec_resize (objects, n_objects);
if (vec_bytes (objects) > 0) /* stupid warning be gone */
- memset (objects, ~0, vec_bytes (objects));
+ clib_memset (objects, ~0, vec_bytes (objects));
objects_used = 0;
/* Allocate initial heap. */
diff --git a/src/vppinfra/test_qhash.c b/src/vppinfra/test_qhash.c
index 68e8cbc2bde..a520fa4bd77 100644
--- a/src/vppinfra/test_qhash.c
+++ b/src/vppinfra/test_qhash.c
@@ -54,7 +54,7 @@ test_qhash_main (unformat_input_t * input)
test_qhash_main_t _tm, *tm = &_tm;
uword i, iter;
- memset (tm, 0, sizeof (tm[0]));
+ clib_memset (tm, 0, sizeof (tm[0]));
tm->n_iter = 10;
tm->seed = 1;
tm->n_keys = 10;
diff --git a/src/vppinfra/test_serialize.c b/src/vppinfra/test_serialize.c
index 09f38082313..5c931b76023 100644
--- a/src/vppinfra/test_serialize.c
+++ b/src/vppinfra/test_serialize.c
@@ -145,7 +145,7 @@ test_serialize_main (unformat_input_t * input)
serialize_main_t *um = &tm->unserialize_main;
uword i;
- memset (tm, 0, sizeof (tm[0]));
+ clib_memset (tm, 0, sizeof (tm[0]));
tm->n_iter = 100;
tm->seed = 1;
tm->max_len = 128;
diff --git a/src/vppinfra/test_time_range.c b/src/vppinfra/test_time_range.c
index 2ec6e13a9d5..a22ef3a2c08 100644
--- a/src/vppinfra/test_time_range.c
+++ b/src/vppinfra/test_time_range.c
@@ -55,7 +55,7 @@ test_time_range_main (unformat_input_t * input)
fformat (stdout, "Test daylight time rules:\n");
- memset (cp, 0, sizeof (*cp));
+ clib_memset (cp, 0, sizeof (*cp));
/* Just before DST starts */
cp->year = 2011;
diff --git a/src/vppinfra/test_timing_wheel.c b/src/vppinfra/test_timing_wheel.c
index 7cf6e0c33f4..48020d520a0 100644
--- a/src/vppinfra/test_timing_wheel.c
+++ b/src/vppinfra/test_timing_wheel.c
@@ -97,7 +97,7 @@ test_timing_wheel_main (unformat_input_t * input)
timing_wheel_t *w = &tm->timing_wheel;
uword iter, i;
- memset (tm, 0, sizeof (tm[0]));
+ clib_memset (tm, 0, sizeof (tm[0]));
tm->n_iter = 10;
tm->time_per_status_update = 0;
tm->n_events = 100;
diff --git a/src/vppinfra/test_tw_timer.c b/src/vppinfra/test_tw_timer.c
index bde958f3ca2..90fbc9e18b7 100644
--- a/src/vppinfra/test_tw_timer.c
+++ b/src/vppinfra/test_tw_timer.c
@@ -246,7 +246,7 @@ test2_single (tw_timer_test_main_t * tm)
for (i = 0; i < tm->ntimers; i++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
do
{
@@ -293,7 +293,7 @@ test2_single (tw_timer_test_main_t * tm)
for (j = 0; j < tm->ntimers / 4; j++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
do
{
@@ -384,7 +384,7 @@ test2_double (tw_timer_test_main_t * tm)
for (i = 0; i < tm->ntimers; i++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
do
{
@@ -430,7 +430,7 @@ test2_double (tw_timer_test_main_t * tm)
for (j = 0; j < tm->ntimers / 4; j++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
do
{
@@ -528,7 +528,7 @@ test2_double_updates (tw_timer_test_main_t * tm)
for (i = 0; i < tm->ntimers; i++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
expiration_time = get_expiration_time (tm);
max_expiration_time = clib_max (expiration_time, max_expiration_time);
@@ -635,7 +635,7 @@ test2_triple (tw_timer_test_main_t * tm)
for (i = 0; i < tm->ntimers; i++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
do
{
@@ -681,7 +681,7 @@ test2_triple (tw_timer_test_main_t * tm)
for (j = 0; j < tm->ntimers / 4; j++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
do
{
@@ -775,7 +775,7 @@ test2_triple_ov (tw_timer_test_main_t * tm)
for (i = 0; i < tm->ntimers; i++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
do
{
@@ -822,7 +822,7 @@ test2_triple_ov (tw_timer_test_main_t * tm)
for (j = 0; j < tm->ntimers / 4; j++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
do
{
@@ -916,7 +916,7 @@ test1_single (tw_timer_test_main_t * tm)
expected_to_expire = timer_arg + offset;
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
e->expected_to_expire = expected_to_expire;
e->stop_timer_handle = tw_timer_start_2t_1w_2048sl
(&tm->single_wheel, e - tm->test_elts, 1 /* timer id */ ,
@@ -973,7 +973,7 @@ test1_double (tw_timer_test_main_t * tm)
for (i = 0; i < tm->ntimers; i++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
e->expected_to_expire = i + offset + 1;
e->stop_timer_handle = tw_timer_start_16t_2w_512sl
@@ -1039,7 +1039,7 @@ test3_triple_double (tw_timer_test_main_t * tm)
/* Prime the pump */
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
/* 1 glacier ring tick from now */
expiration_time = TW_SLOTS_PER_RING * TW_SLOTS_PER_RING;
@@ -1117,7 +1117,7 @@ test4_double_double (tw_timer_test_main_t * tm)
for (i = 0; i < tm->ntimers; i++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
expiration_time = 512;
@@ -1203,7 +1203,7 @@ test5_double (tw_timer_test_main_t * tm)
for (i = 0; i < tm->ntimers; i++)
{
pool_get (tm->test_elts, e);
- memset (e, 0, sizeof (*e));
+ clib_memset (e, 0, sizeof (*e));
expiration_time = i + 1;
@@ -1260,7 +1260,7 @@ timer_test_command_fn (tw_timer_test_main_t * tm, unformat_input_t * input)
int is_test5 = 0;
int overflow = 0;
- memset (tm, 0, sizeof (*tm));
+ clib_memset (tm, 0, sizeof (*tm));
/* Default values */
tm->ntimers = 100000;
tm->seed = 0xDEADDABEB00BFACE;
diff --git a/src/vppinfra/test_vhash.c b/src/vppinfra/test_vhash.c
index f5aa5e21aec..594d46c38df 100644
--- a/src/vppinfra/test_vhash.c
+++ b/src/vppinfra/test_vhash.c
@@ -471,7 +471,7 @@ test_vhash_main (unformat_input_t * input)
vhash_t *vh = &tm->vhash;
uword i, j;
- memset (tm, 0, sizeof (tm[0]));
+ clib_memset (tm, 0, sizeof (tm[0]));
tm->n_iter = 100;
tm->seed = 1;
tm->n_keys = 1;
diff --git a/src/vppinfra/time.c b/src/vppinfra/time.c
index d647e670dad..afb1a867ec7 100644
--- a/src/vppinfra/time.c
+++ b/src/vppinfra/time.c
@@ -177,7 +177,7 @@ os_cpu_clock_frequency (void)
void
clib_time_init (clib_time_t * c)
{
- memset (c, 0, sizeof (c[0]));
+ clib_memset (c, 0, sizeof (c[0]));
c->clocks_per_second = os_cpu_clock_frequency ();
c->seconds_per_clock = 1 / c->clocks_per_second;
c->log2_clocks_per_second = min_log2_u64 ((u64) c->clocks_per_second);
diff --git a/src/vppinfra/time_range.c b/src/vppinfra/time_range.c
index e502ca358db..ea95284ea03 100644
--- a/src/vppinfra/time_range.c
+++ b/src/vppinfra/time_range.c
@@ -19,7 +19,7 @@ void
clib_timebase_init (clib_timebase_t * tb, i32 timezone_offset_in_hours,
clib_timebase_daylight_time_t daylight_type)
{
- memset (tb, 0, sizeof (*tb));
+ clib_memset (tb, 0, sizeof (*tb));
clib_time_init (&tb->clib_time);
tb->time_zero = unix_time_now ();
diff --git a/src/vppinfra/timer.c b/src/vppinfra/timer.c
index 8bbab653ec0..e1e32eb285f 100644
--- a/src/vppinfra/timer.c
+++ b/src/vppinfra/timer.c
@@ -132,7 +132,7 @@ timer_interrupt (int signum)
{
/* Set timer for to go off in future. */
struct itimerval itv;
- memset (&itv, 0, sizeof (itv));
+ clib_memset (&itv, 0, sizeof (itv));
f64_to_tv (dt, &itv.it_value);
if (setitimer (ITIMER_REAL, &itv, 0) < 0)
clib_unix_error ("sititmer");
@@ -146,7 +146,7 @@ timer_block (sigset_t * save)
{
sigset_t block_timer;
- memset (&block_timer, 0, sizeof (block_timer));
+ clib_memset (&block_timer, 0, sizeof (block_timer));
sigaddset (&block_timer, TIMER_SIGNAL);
sigprocmask (SIG_BLOCK, &block_timer, save);
}
@@ -175,7 +175,7 @@ timer_call (timer_func_t * func, any arg, f64 dt)
/* Initialize time_resolution before first call to timer_interrupt */
time_resolution = 0.75 / (f64) HZ;
- memset (&sa, 0, sizeof (sa));
+ clib_memset (&sa, 0, sizeof (sa));
sa.sa_handler = timer_interrupt;
if (sigaction (TIMER_SIGNAL, &sa, 0) < 0)
diff --git a/src/vppinfra/timing_wheel.c b/src/vppinfra/timing_wheel.c
index 09a46d52252..bbf3012ffd8 100644
--- a/src/vppinfra/timing_wheel.c
+++ b/src/vppinfra/timing_wheel.c
@@ -184,7 +184,7 @@ free_elt_vector (timing_wheel_t * w, timing_wheel_elt_t * ev)
{
/* Poison free elements so we never use them by mistake. */
if (CLIB_DEBUG > 0)
- memset (ev, ~0, vec_len (ev) * sizeof (ev[0]));
+ clib_memset (ev, ~0, vec_len (ev) * sizeof (ev[0]));
_vec_len (ev) = 0;
vec_add1 (w->free_elt_vectors, ev);
}
diff --git a/src/vppinfra/tw_timer_template.c b/src/vppinfra/tw_timer_template.c
index 9c9bb977d5e..11a38890f9c 100644
--- a/src/vppinfra/tw_timer_template.c
+++ b/src/vppinfra/tw_timer_template.c
@@ -301,7 +301,7 @@ TW (tw_timer_start) (TWT (tw_timer_wheel) * tw, u32 user_id, u32 timer_id,
ASSERT (interval);
pool_get (tw->timers, t);
- memset (t, 0xff, sizeof (*t));
+ clib_memset (t, 0xff, sizeof (*t));
t->user_handle = TW (make_internal_timer_handle) (user_id, timer_id);
@@ -411,7 +411,7 @@ TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw,
int ring, slot;
tw_timer_wheel_slot_t *ts;
TWT (tw_timer) * t;
- memset (tw, 0, sizeof (*tw));
+ clib_memset (tw, 0, sizeof (*tw));
tw->expired_timer_callback = expired_timer_callback;
tw->max_expirations = max_expirations;
if (timer_interval_in_seconds == 0.0)
@@ -432,7 +432,7 @@ TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw,
{
ts = &tw->w[ring][slot];
pool_get (tw->timers, t);
- memset (t, 0xff, sizeof (*t));
+ clib_memset (t, 0xff, sizeof (*t));
t->next = t->prev = t - tw->timers;
ts->head_index = t - tw->timers;
}
@@ -441,7 +441,7 @@ TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw,
#if TW_OVERFLOW_VECTOR > 0
ts = &tw->overflow;
pool_get (tw->timers, t);
- memset (t, 0xff, sizeof (*t));
+ clib_memset (t, 0xff, sizeof (*t));
t->next = t->prev = t - tw->timers;
ts->head_index = t - tw->timers;
#endif
@@ -490,7 +490,7 @@ void TW (tw_timer_wheel_free) (TWT (tw_timer_wheel) * tw)
pool_put (tw->timers, head);
#endif
- memset (tw, 0, sizeof (*tw));
+ clib_memset (tw, 0, sizeof (*tw));
}
/**
diff --git a/src/vppinfra/unformat.c b/src/vppinfra/unformat.c
index 365cdb15700..da7622a90a8 100644
--- a/src/vppinfra/unformat.c
+++ b/src/vppinfra/unformat.c
@@ -335,7 +335,7 @@ unformat_token (unformat_input_t * input, va_list * va)
if (!token_chars)
token_chars = (u8 *) "a-zA-Z0-9_";
- memset (map, 0, sizeof (map));
+ clib_memset (map, 0, sizeof (map));
for (s = token_chars; *s;)
{
/* Parse range. */
@@ -576,9 +576,9 @@ unformat_float (unformat_input_t * input, va_list * va)
uword signs[2], sign_index = 0;
uword n_input = 0;
- memset (values, 0, sizeof (values));
- memset (n_digits, 0, sizeof (n_digits));
- memset (signs, 0, sizeof (signs));
+ clib_memset (values, 0, sizeof (values));
+ clib_memset (n_digits, 0, sizeof (n_digits));
+ clib_memset (signs, 0, sizeof (signs));
while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
{
diff --git a/src/vppinfra/valloc.c b/src/vppinfra/valloc.c
index cd1d89bb9a1..927802bfeb1 100644
--- a/src/vppinfra/valloc.c
+++ b/src/vppinfra/valloc.c
@@ -68,7 +68,7 @@ clib_valloc_add_chunk (clib_valloc_main_t * vam,
if (index == ~0 || template->baseva < ch->baseva)
{
pool_get (vam->chunks, new_ch);
- memset (new_ch, 0, sizeof (*new_ch));
+ clib_memset (new_ch, 0, sizeof (*new_ch));
if (index != ~0)
{
@@ -102,7 +102,7 @@ clib_valloc_add_chunk (clib_valloc_main_t * vam,
index = ch - vam->chunks;
pool_get (vam->chunks, new_ch);
- memset (new_ch, 0, sizeof (*new_ch));
+ clib_memset (new_ch, 0, sizeof (*new_ch));
ch = pool_elt_at_index (vam->chunks, index);
@@ -130,7 +130,7 @@ clib_valloc_init (clib_valloc_main_t * vam, clib_valloc_chunk_t * template,
int need_lock)
{
ASSERT (template && template->baseva && template->size);
- memset (vam, 0, sizeof (*vam));
+ clib_memset (vam, 0, sizeof (*vam));
if (need_lock)
clib_spinlock_init (&vam->lock);
@@ -180,7 +180,7 @@ clib_valloc_alloc (clib_valloc_main_t * vam, uword size,
pool_get (vam->chunks, new_ch);
/* ch might have just moved */
ch = pool_elt_at_index (vam->chunks, index);
- memset (new_ch, 0, sizeof (*new_ch));
+ clib_memset (new_ch, 0, sizeof (*new_ch));
new_ch->next = new_ch->prev = ~0;
new_ch->baseva = ch->baseva + size;
new_ch->size = ch->size - size;
@@ -271,7 +271,7 @@ clib_valloc_free (clib_valloc_main_t * vam, uword baseva)
next_ch->prev = ch->prev;
}
ASSERT (ch - vam->chunks != vam->first_index);
- memset (ch, 0xfe, sizeof (*ch));
+ clib_memset (ch, 0xfe, sizeof (*ch));
pool_put (vam->chunks, ch);
/* See about combining with next elt */
ch = prev_ch;
@@ -295,7 +295,7 @@ clib_valloc_free (clib_valloc_main_t * vam, uword baseva)
n2_ch->prev = ch - vam->chunks;
}
ASSERT (next_ch - vam->chunks != vam->first_index);
- memset (next_ch, 0xfe, sizeof (*ch));
+ clib_memset (next_ch, 0xfe, sizeof (*ch));
pool_put (vam->chunks, next_ch);
}
}
diff --git a/src/vppinfra/vec.c b/src/vppinfra/vec.c
index a0b3e038af1..1e0164a9e34 100644
--- a/src/vppinfra/vec.c
+++ b/src/vppinfra/vec.c
@@ -59,7 +59,7 @@ vec_resize_allocate_memory (void *v,
new = clib_mem_alloc_aligned_at_offset (data_bytes, data_align, header_bytes, 1 /* yes, call os_out_of_memory */
);
data_bytes = clib_mem_size (new);
- memset (new, 0, data_bytes);
+ clib_memset (new, 0, data_bytes);
v = new + header_bytes;
_vec_len (v) = length_increment;
return v;
@@ -100,7 +100,7 @@ vec_resize_allocate_memory (void *v,
v = new;
/* Zero new memory. */
- memset (v + old_alloc_bytes, 0, new_alloc_bytes - old_alloc_bytes);
+ clib_memset (v + old_alloc_bytes, 0, new_alloc_bytes - old_alloc_bytes);
return v + header_bytes;
}
diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h
index 1b0378fe063..dc7b908a3b5 100644
--- a/src/vppinfra/vec.h
+++ b/src/vppinfra/vec.h
@@ -423,7 +423,7 @@ do { \
vec_resize_ha ((V), 1 + (_v(i) - _v(l)), (H), (A)); \
/* Must zero new space since user may have previously \
used e.g. _vec_len (v) -= 10 */ \
- memset ((V) + _v(l), 0, (1 + (_v(i) - _v(l))) * sizeof ((V)[0])); \
+ clib_memset ((V) + _v(l), 0, (1 + (_v(i) - _v(l))) * sizeof ((V)[0])); \
} \
} while (0)
@@ -661,7 +661,7 @@ do { \
memmove ((V) + _v(m) + _v(n), \
(V) + _v(m), \
(_v(l) - _v(m)) * sizeof ((V)[0])); \
- memset ((V) + _v(m), INIT, _v(n) * sizeof ((V)[0])); \
+ clib_memset ((V) + _v(m), INIT, _v(n) * sizeof ((V)[0])); \
} while (0)
/** \brief Insert N vector elements starting at element M,
@@ -794,7 +794,7 @@ do { \
(_v(l) - _v(n) - _v(m)) * sizeof ((V)[0])); \
/* Zero empty space at end (for future re-allocation). */ \
if (_v(n) > 0) \
- memset ((V) + _v(l) - _v(n), 0, _v(n) * sizeof ((V)[0])); \
+ clib_memset ((V) + _v(l) - _v(n), 0, _v(n) * sizeof ((V)[0])); \
_vec_len (V) -= _v(n); \
} while (0)
@@ -883,7 +883,7 @@ do { \
#define vec_zero(var) \
do { \
if (var) \
- memset ((var), 0, vec_len (var) * sizeof ((var)[0])); \
+ clib_memset ((var), 0, vec_len (var) * sizeof ((var)[0])); \
} while (0)
/** \brief Set all vector elements to given value. Null-pointer tolerant.
diff --git a/src/vppinfra/vhash.c b/src/vppinfra/vhash.c
index f9dac0d9ff1..9120f502c91 100644
--- a/src/vppinfra/vhash.c
+++ b/src/vppinfra/vhash.c
@@ -245,7 +245,7 @@ vhash_init (vhash_t * h, u32 log2_n_keys, u32 n_key_u32, u32 * hash_seeds)
uword i, j, m;
vhash_search_bucket_t *b;
- memset (h, 0, sizeof (h[0]));
+ clib_memset (h, 0, sizeof (h[0]));
/* Must have at least 4 keys (e.g. one search bucket). */
log2_n_keys = clib_max (log2_n_keys, 2);