vector: Prevent NULL argument to memcpy.
authorCorey Farrell <git@cfware.com>
Sun, 30 Oct 2016 18:33:12 +0000 (14:33 -0400)
committerCorey Farrell <git@cfware.com>
Sun, 30 Oct 2016 18:46:19 +0000 (13:46 -0500)
Headers declare that memcpy does not accept NULL argument for the first
two parameters.  Add a conditional block to prevent memcpy and ast_free
from running on vectors with NULL element array.

ASTERISK-26526 #close

Change-Id: I988a476bb5fcfcbd3f6d6c6b3e7769e4f9629b71

include/asterisk/vector.h

index c74f0a8..83732e7 100644 (file)
                        typeof((vec)->elems) new_elems = ast_calloc(1,          \
                                new_max * sizeof(*new_elems));                                  \
                        if (new_elems) {                                                                        \
-                               memcpy(new_elems, (vec)->elems,                                 \
-                                       (vec)->current * sizeof(*new_elems));           \
-                               ast_free((vec)->elems);                                                 \
+                               if ((vec)->elems) {                                                             \
+                                       memcpy(new_elems, (vec)->elems,                         \
+                                               (vec)->current * sizeof(*new_elems));   \
+                                       ast_free((vec)->elems);                                         \
+                               }                                                                                               \
                                (vec)->elems = new_elems;                                               \
                                (vec)->max = new_max;                                                   \
                        } else {                                                                                        \