VPP-189 Fix Coverity warnings
[vpp.git] / vppinfra / vppinfra / vec.h
index 79954f3..7017358 100644 (file)
@@ -319,7 +319,7 @@ do {                                                \
   if (_v(l) > 0)                                       \
     {                                                  \
       vec_resize_ha (_v(v), _v(l), (H), (A));          \
-      memcpy (_v(v), (V), _v(l) * sizeof ((V)[0]));    \
+      clib_memcpy (_v(v), (V), _v(l) * sizeof ((V)[0]));\
     }                                                  \
   _v(v);                                               \
 })
@@ -346,7 +346,8 @@ do {                                                \
     @param DST destination 
     @param SRC source
 */
-#define vec_copy(DST,SRC) memcpy (DST, SRC, vec_len (DST) * sizeof ((DST)[0]))
+#define vec_copy(DST,SRC) clib_memcpy (DST, SRC, vec_len (DST) * \
+                                      sizeof ((DST)[0]))
 
 /** \brief Clone a vector. Make a new vector with the 
     same size as a given vector but possibly with a different type.
@@ -543,7 +544,7 @@ do {                                                                                \
   word _v(n) = (N);                                                            \
   word _v(l) = vec_len (V);                                                    \
   V = _vec_resize ((V), _v(n), (_v(l) + _v(n)) * sizeof ((V)[0]), (H), (A));   \
-  memcpy ((V) + _v(l), (E), _v(n) * sizeof ((V)[0]));                          \
+  clib_memcpy ((V) + _v(l), (E), _v(n) * sizeof ((V)[0]));                     \
 } while (0)
 
 /** \brief Add N elements to end of vector V (no header, unspecified alignment)
@@ -705,7 +706,8 @@ do {                                                        \
   memmove ((V) + _v(m) + _v(n),                                \
           (V) + _v(m),                                 \
           (_v(l) - _v(m)) * sizeof ((V)[0]));          \
-  memcpy  ((V) + _v(m), (E), _v(n) * sizeof ((V)[0])); \
+  clib_memcpy ((V) + _v(m), (E),                       \
+              _v(n) * sizeof ((V)[0]));                \
 } while (0)
 
 /** \brief Insert N vector elements starting at element M, 
@@ -779,7 +781,7 @@ do {                                                                        \
                                                                        \
   v1 = _vec_resize ((v1), _v(l2),                                      \
                    (_v(l1) + _v(l2)) * sizeof ((v1)[0]), 0, 0);        \
-  memcpy ((v1) + _v(l1), (v2), _v(l2) * sizeof ((v2)[0]));             \
+  clib_memcpy ((v1) + _v(l1), (v2), _v(l2) * sizeof ((v2)[0]));                \
 } while (0)
 
 /** \brief Append v2 after v1. Result in v1. Specified alignment.
@@ -795,7 +797,7 @@ do {                                                                        \
                                                                        \
   v1 = _vec_resize ((v1), _v(l2),                                      \
                    (_v(l1) + _v(l2)) * sizeof ((v1)[0]), 0, align);    \
-  memcpy ((v1) + _v(l1), (v2), _v(l2) * sizeof ((v2)[0]));             \
+  clib_memcpy ((v1) + _v(l1), (v2), _v(l2) * sizeof ((v2)[0]));                \
 } while (0)
 
 /** \brief Prepend v2 before v1. Result in v1.
@@ -811,7 +813,7 @@ do {                                                                    \
   v1 = _vec_resize ((v1), _v(l2),                                       \
                    (_v(l1) + _v(l2)) * sizeof ((v1)[0]), 0, 0);        \
   memmove ((v1) + _v(l2), (v1), _v(l1) * sizeof ((v1)[0]));             \
-  memcpy ((v1), (v2), _v(l2) * sizeof ((v2)[0]));                       \
+  clib_memcpy ((v1), (v2), _v(l2) * sizeof ((v2)[0]));                  \
 } while (0)
 
 /** \brief Prepend v2 before v1. Result in v1. Specified alignment
@@ -828,7 +830,7 @@ do {                                                                    \
   v1 = _vec_resize ((v1), _v(l2),                                       \
                    (_v(l1) + _v(l2)) * sizeof ((v1)[0]), 0, align);    \
   memmove ((v1) + _v(l2), (v1), _v(l1) * sizeof ((v1)[0]));             \
-  memcpy ((v1), (v2), _v(l2) * sizeof ((v2)[0]));                       \
+  clib_memcpy ((v1), (v2), _v(l2) * sizeof ((v2)[0]));                  \
 } while (0)
 
 
@@ -888,33 +890,6 @@ do {                                               \
   (_v(cmp) < 0 ? -1 : (_v(cmp) > 0 ? +1 : 0));         \
 })
 
-/**\brief Sort a vector with qsort via user's comparison body
-
-   Example to sort an integer vector:
-     int * int_vec = ...;
-     vec_sort (int_vec, i0, i1, i0[0] - i1[0]);
-
-   WARNING: vec_sort requires an executable stack segment.
-   If at all possible, use vec_sort_with_function () instead.
-
-   @param vec vector to sort
-   @param v0 vector element
-   @param v1 vector element
-   @param body vector comparision expression
-*/
-
-#define vec_sort(vec,v0,v1,body)                                       \
-do {                                                                   \
-  int _vec_sort_compare (const void * _v0,                             \
-                        const void * _v1)                              \
-  {                                                                    \
-    __typeof__ (vec) v0 = (__typeof__ (vec)) _v0;                      \
-    __typeof__ (vec) v1 = (__typeof__ (vec)) _v1;                      \
-    return (int) (body);                                               \
-  }                                                                    \
-  qsort (vec, vec_len (vec), sizeof (vec[0]), _vec_sort_compare);      \
-} while (0)
-
 /** \brief Sort a vector using the supplied element comparison function
 
     @param vec vector to sort
@@ -936,12 +911,12 @@ do {                                                              \
     vec_reset_length (V);                       \
     vec_validate ((V), (L));                    \
     if ((S) && (L))                             \
-        memcpy ((V), (S), (L));                 \
+        clib_memcpy ((V), (S), (L));            \
     (V)[(L)] = 0;                               \
   } while (0)
 
 
-/** \brief .
+/** \brief Test whether a vector is a NULL terminated c-string.
 
     @param V (possibly NULL) pointer to a vector. 
     @return BOOLEAN indicating if the vector c-string is null terminated.
@@ -949,7 +924,7 @@ do {                                                                \
 #define vec_c_string_is_terminated(V)                   \
   (((V) != 0) && (vec_len (V) != 0) && ((V)[vec_len ((V)) - 1] == 0))
 
-/** \brief (If necessary) Null terminate a vector containing a c-string.
+/** \brief (If necessary) NULL terminate a vector containing a c-string.
 
     @param V (possibly NULL) pointer to a vector. 
     @return V (value-result macro parameter)