X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fdynamic-array.h;h=0b488a39cd52f95b785f2f3a52ee48f6c3e9cd0b;hp=483db363122ebbc5a6339cd5ec144a2181922066;hb=a321667af6f25a77e32787fe89ad306786f7b29a;hpb=14c4262b940630bbb75f68b8c2eaef2b134a62d9 diff --git a/src/common/dynamic-array.h b/src/common/dynamic-array.h index 483db3631..0b488a39c 100644 --- a/src/common/dynamic-array.h +++ b/src/common/dynamic-array.h @@ -1,18 +1,8 @@ /* - * Copyright (C) 2019 - Jérémie Galarneau + * Copyright (C) 2019 Jérémie Galarneau * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License, version 2.1 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: LGPL-2.1-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef LTTNG_DYNAMIC_ARRAY_H @@ -66,6 +56,25 @@ void *lttng_dynamic_array_get_element(const struct lttng_dynamic_array *array, return array->buffer.data + (element_index * array->element_size); } +/* + * Set the array's element count to new_element_count. Any added element will + * be zeroed. + * + * Be careful to expand the array's element count _before_ calling out external + * APIs (e.g. read(3)) which may populate the buffer as setting the element + * count after will zero-out the result of the operation. + * + * Shrinking an array does not zero the old content. If the buffer may contain + * sensititve information, it must be cleared manually _before_ changing the + * size. + * + * NOTE: It is striclty _invalid_ to access memory after _size_, regardless + * of prior calls to set_capacity(). + */ +LTTNG_HIDDEN +int lttng_dynamic_array_set_count(struct lttng_dynamic_array *array, + size_t new_element_count); + /* * Add an element to the end of a dynamic array. The array's element count is * increased by one and its underlying capacity is adjusted automatically. @@ -89,6 +98,9 @@ int lttng_dynamic_array_remove_element(struct lttng_dynamic_array *array, LTTNG_HIDDEN void lttng_dynamic_array_reset(struct lttng_dynamic_array *array); +/* Remove all elements from the dynamic array. */ +LTTNG_HIDDEN +void lttng_dynamic_array_clear(struct lttng_dynamic_array *array); /* * Specialization of lttng_dynamic_array for pointers. This utility @@ -154,4 +166,9 @@ LTTNG_HIDDEN void lttng_dynamic_pointer_array_reset( struct lttng_dynamic_pointer_array *array); +/* Remove all elements from the dynamic pointer array. */ +LTTNG_HIDDEN +void lttng_dynamic_pointer_array_clear( + struct lttng_dynamic_pointer_array *array); + #endif /* LTTNG_DYNAMIC_ARRAY_H */