Skip to content

Commit

Permalink
API: make it clear that add_info() wants non-NULL name+value
Browse files Browse the repository at this point in the history
It'd crash otherwise.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Jul 25, 2023
1 parent 56386eb commit 293206f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hwloc/topology.c
Expand Up @@ -496,6 +496,11 @@ int hwloc__add_info(struct hwloc_infos_s *infos, const char *name, const char *v
unsigned count;
struct hwloc_info_s *array;

if (!name || !value) {
errno = EINVAL;
return -1;
}

if (hwloc__realloc_infos(infos, 1) < 0)
return -1;

Expand Down Expand Up @@ -525,6 +530,12 @@ int hwloc__add_info_nodup(struct hwloc_infos_s *infos,
struct hwloc_info_s *array = infos->array;
unsigned count = infos->count;
unsigned i;

if (!name || !value) {
errno = EINVAL;
return -1;
}

for(i=0; i<count; i++) {
if (!strcmp(array[i].name, name)) {
if (replace) {
Expand Down
2 changes: 2 additions & 0 deletions include/hwloc.h
Expand Up @@ -1162,6 +1162,8 @@ hwloc_get_info_by_name(struct hwloc_infos_s *infos, const char *name) __hwloc_at
*
* The input strings are copied before being added in the object infos.
*
* \p name and \p value must be non \c NULL.
*
* \return \c 0 on success, \c -1 on error.
*
* \note This function may be used to enforce object colors in the lstopo
Expand Down

0 comments on commit 293206f

Please sign in to comment.