c11 safe string handling support
Change-Id: Ied34720ca5a6e6e717eea4e86003e854031b6eab
Signed-off-by: Dave Barach <dave@barachs.net>
diff --git a/src/vppinfra/asm_x86.c b/src/vppinfra/asm_x86.c
index 16e41c2..e6e00ce 100644
--- a/src/vppinfra/asm_x86.c
+++ b/src/vppinfra/asm_x86.c
@@ -1500,7 +1500,7 @@
/* 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 5949e2b..f6515b8 100644
--- a/src/vppinfra/bihash_16_8.h
+++ b/src/vppinfra/bihash_16_8.h
@@ -36,7 +36,7 @@
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 d30625d..3e83ad2 100644
--- a/src/vppinfra/bihash_16_8_32.h
+++ b/src/vppinfra/bihash_16_8_32.h
@@ -38,7 +38,7 @@
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 c028352..6d1cdd3 100644
--- a/src/vppinfra/bihash_24_8.h
+++ b/src/vppinfra/bihash_24_8.h
@@ -36,7 +36,7 @@
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 fe57ba0..b85adb0 100644
--- a/src/vppinfra/bihash_40_8.h
+++ b/src/vppinfra/bihash_40_8.h
@@ -37,7 +37,7 @@
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 9aebe66..328a90b 100644
--- a/src/vppinfra/bihash_48_8.h
+++ b/src/vppinfra/bihash_48_8.h
@@ -37,7 +37,7 @@
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 752597e..e218f4b 100644
--- a/src/vppinfra/bihash_template.c
+++ b/src/vppinfra/bihash_template.c
@@ -203,7 +203,7 @@
(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 @@
* 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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
* 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 @@
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 @@
/* 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 @@
{
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 6fe334d..a3d07c8 100644
--- a/src/vppinfra/cuckoo_8_8.h
+++ b/src/vppinfra/cuckoo_8_8.h
@@ -64,7 +64,7 @@
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 595bd1c..119a407 100644
--- a/src/vppinfra/cuckoo_template.c
+++ b/src/vppinfra/cuckoo_template.c
@@ -180,7 +180,7 @@
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_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 @@
{
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_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 @@
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 e445b39..d28500d 100644
--- a/src/vppinfra/dlist.h
+++ b/src/vppinfra/dlist.h
@@ -36,7 +36,7 @@
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 931fbcc..a8c5d30 100644
--- a/src/vppinfra/elf.c
+++ b/src/vppinfra/elf.c
@@ -983,7 +983,7 @@
{
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)
{
- 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 c57b06f..cceb13e 100644
--- a/src/vppinfra/elf.h
+++ b/src/vppinfra/elf.h
@@ -919,7 +919,7 @@
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 c6902eb..8e3f6c1 100644
--- a/src/vppinfra/elog.c
+++ b/src/vppinfra/elog.c
@@ -469,7 +469,7 @@
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_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 1369245..034168e 100644
--- a/src/vppinfra/fheap.c
+++ b/src/vppinfra/fheap.c
@@ -167,7 +167,7 @@
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 6d4965f..1dbd52b 100644
--- a/src/vppinfra/fheap.h
+++ b/src/vppinfra/fheap.h
@@ -89,7 +89,7 @@
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 5b4c76d..e3b7b41 100644
--- a/src/vppinfra/fifo.c
+++ b/src/vppinfra/fifo.c
@@ -121,7 +121,7 @@
/* 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 9227256..d7a621c 100644
--- a/src/vppinfra/flowhash_template.h
+++ b/src/vppinfra/flowhash_template.h
@@ -374,7 +374,7 @@
/* 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 e2fd84b..886f03d 100644
--- a/src/vppinfra/format.c
+++ b/src/vppinfra/format.c
@@ -139,13 +139,13 @@
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 9a3a342..9434447 100644
--- a/src/vppinfra/format.h
+++ b/src/vppinfra/format.h
@@ -153,7 +153,7 @@
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 @@
{
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 ea11a96..3f8a3e8 100644
--- a/src/vppinfra/graph.c
+++ b/src/vppinfra/graph.c
@@ -102,7 +102,7 @@
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 abc7c4c..2ff8ebf 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 @@
{
/* 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 36a7006..892b2ea 100644
--- a/src/vppinfra/hash.h
+++ b/src/vppinfra/hash.h
@@ -496,7 +496,7 @@
_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 2a5fb5c..f7b1f6b 100644
--- a/src/vppinfra/heap.c
+++ b/src/vppinfra/heap.c
@@ -698,7 +698,7 @@
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 f76c945..b6e9f02 100644
--- a/src/vppinfra/heap.h
+++ b/src/vppinfra/heap.h
@@ -260,7 +260,7 @@
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 4645378..337c5a3 100644
--- a/src/vppinfra/lock.h
+++ b/src/vppinfra/lock.h
@@ -57,7 +57,7 @@
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 @@
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 1900aa8..6891336 100644
--- a/src/vppinfra/maplog.c
+++ b/src/vppinfra/maplog.c
@@ -42,7 +42,7 @@
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 @@
(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 @@
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 9cc62ed..04c26d2 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 8afb050..6268709 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -73,7 +73,7 @@
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 @@
{
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 6519d86..64dff4e 100644
--- a/src/vppinfra/memcpy_avx2.h
+++ b/src/vppinfra/memcpy_avx2.h
@@ -109,7 +109,7 @@
}
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 6798250..e524526 100644
--- a/src/vppinfra/memcpy_avx512.h
+++ b/src/vppinfra/memcpy_avx512.h
@@ -139,7 +139,7 @@
}
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 5e4bf7d..2dd9399 100644
--- a/src/vppinfra/memcpy_sse3.h
+++ b/src/vppinfra/memcpy_sse3.h
@@ -183,7 +183,7 @@
})
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 b694cc7..e09d719 100644
--- a/src/vppinfra/mhash.c
+++ b/src/vppinfra/mhash.c
@@ -202,7 +202,7 @@
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 0a62943..ba5bbc9 100644
--- a/src/vppinfra/mheap.c
+++ b/src/vppinfra/mheap.c
@@ -935,7 +935,7 @@
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 @@
(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 @@
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_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 @@
{
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 f6eecaa..52c29b3 100644
--- a/src/vppinfra/phash.c
+++ b/src/vppinfra/phash.c
@@ -605,7 +605,7 @@
/* 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 746a0fd..3dc59c7 100644
--- a/src/vppinfra/phash.h
+++ b/src/vppinfra/phash.h
@@ -168,7 +168,7 @@
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 ed83b41..ed04eb6 100644
--- a/src/vppinfra/pool.c
+++ b/src/vppinfra/pool.c
@@ -107,7 +107,8 @@
/* 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 f4e38c4..3b5a175 100644
--- a/src/vppinfra/qhash.c
+++ b/src/vppinfra/qhash.c
@@ -61,7 +61,7 @@
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 @@
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 @@
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 df03698..52de5d3 100644
--- a/src/vppinfra/random_buffer.c
+++ b/src/vppinfra/random_buffer.c
@@ -63,7 +63,7 @@
{
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 a098aa2..ef9cf03 100644
--- a/src/vppinfra/serialize.c
+++ b/src/vppinfra/serialize.c
@@ -572,7 +572,7 @@
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 @@
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 @@
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 @@
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 @@
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 892517b..5598871 100644
--- a/src/vppinfra/slist.c
+++ b/src/vppinfra/slist.c
@@ -54,7 +54,7 @@
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 @@
* 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 29b2a94..990d0f7 100644
--- a/src/vppinfra/socket.c
+++ b/src/vppinfra/socket.c
@@ -73,7 +73,7 @@
{
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 @@
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 @@
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_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 4f9e950..b5f0058 100644
--- a/src/vppinfra/socket.h
+++ b/src/vppinfra/socket.h
@@ -168,7 +168,7 @@
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 ba21e7b..b90f432 100644
--- a/src/vppinfra/string.c
+++ b/src/vppinfra/string.c
@@ -85,6 +85,25 @@
}
}
+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 2c794ba..5c1d826 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 @@
#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 @@
return count;
}
-
#endif /* included_clib_string_h */
/*
diff --git a/src/vppinfra/test_cuckoo_bihash.c b/src/vppinfra/test_cuckoo_bihash.c
index eb17eed..3e63f0b 100644
--- a/src/vppinfra/test_cuckoo_bihash.c
+++ b/src/vppinfra/test_cuckoo_bihash.c
@@ -413,7 +413,7 @@
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 84fe077..3bed954 100644
--- a/src/vppinfra/test_elf.c
+++ b/src/vppinfra/test_elf.c
@@ -72,7 +72,7 @@
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 @@
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 54a1f09..0fd6bf7 100644
--- a/src/vppinfra/test_heap.c
+++ b/src/vppinfra/test_heap.c
@@ -95,7 +95,7 @@
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 f3ff662..b51f7f5 100644
--- a/src/vppinfra/test_maplog.c
+++ b/src/vppinfra/test_maplog.c
@@ -79,7 +79,7 @@
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 @@
}
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 f6923a9..de94065 100644
--- a/src/vppinfra/test_mheap.c
+++ b/src/vppinfra/test_mheap.c
@@ -154,7 +154,7 @@
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 68e8cbc..a520fa4 100644
--- a/src/vppinfra/test_qhash.c
+++ b/src/vppinfra/test_qhash.c
@@ -54,7 +54,7 @@
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 09f3808..5c931b7 100644
--- a/src/vppinfra/test_serialize.c
+++ b/src/vppinfra/test_serialize.c
@@ -145,7 +145,7 @@
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 2ec6e13..a22ef3a 100644
--- a/src/vppinfra/test_time_range.c
+++ b/src/vppinfra/test_time_range.c
@@ -55,7 +55,7 @@
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 7cf6e0c..48020d5 100644
--- a/src/vppinfra/test_timing_wheel.c
+++ b/src/vppinfra/test_timing_wheel.c
@@ -97,7 +97,7 @@
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 bde958f..90fbc9e 100644
--- a/src/vppinfra/test_tw_timer.c
+++ b/src/vppinfra/test_tw_timer.c
@@ -246,7 +246,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
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 f5aa5e2..594d46c 100644
--- a/src/vppinfra/test_vhash.c
+++ b/src/vppinfra/test_vhash.c
@@ -471,7 +471,7 @@
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 d647e67..afb1a86 100644
--- a/src/vppinfra/time.c
+++ b/src/vppinfra/time.c
@@ -177,7 +177,7 @@
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 e502ca3..ea95284 100644
--- a/src/vppinfra/time_range.c
+++ b/src/vppinfra/time_range.c
@@ -19,7 +19,7 @@
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 8bbab65..e1e32eb 100644
--- a/src/vppinfra/timer.c
+++ b/src/vppinfra/timer.c
@@ -132,7 +132,7 @@
{
/* 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 @@
{
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 @@
/* 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 09a46d5..bbf3012 100644
--- a/src/vppinfra/timing_wheel.c
+++ b/src/vppinfra/timing_wheel.c
@@ -184,7 +184,7 @@
{
/* 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 9c9bb97..11a3889 100644
--- a/src/vppinfra/tw_timer_template.c
+++ b/src/vppinfra/tw_timer_template.c
@@ -301,7 +301,7 @@
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 @@
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 @@
{
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 @@
#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 @@
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 365cdb1..da7622a 100644
--- a/src/vppinfra/unformat.c
+++ b/src/vppinfra/unformat.c
@@ -335,7 +335,7 @@
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 @@
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 cd1d89b..927802b 100644
--- a/src/vppinfra/valloc.c
+++ b/src/vppinfra/valloc.c
@@ -68,7 +68,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 a0b3e03..1e0164a 100644
--- a/src/vppinfra/vec.c
+++ b/src/vppinfra/vec.c
@@ -59,7 +59,7 @@
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 @@
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 1b0378f..dc7b908 100644
--- a/src/vppinfra/vec.h
+++ b/src/vppinfra/vec.h
@@ -423,7 +423,7 @@
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 @@
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 @@
(_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 @@
#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 f9dac0d..9120f50 100644
--- a/src/vppinfra/vhash.c
+++ b/src/vppinfra/vhash.c
@@ -245,7 +245,7 @@
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);