Skip to content

Commit 293206f

Browse files
committed
API: make it clear that add_info() wants non-NULL name+value
It'd crash otherwise. Signed-off-by: Brice Goglin <[email protected]>
1 parent 56386eb commit 293206f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

hwloc/topology.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ int hwloc__add_info(struct hwloc_infos_s *infos, const char *name, const char *v
496496
unsigned count;
497497
struct hwloc_info_s *array;
498498

499+
if (!name || !value) {
500+
errno = EINVAL;
501+
return -1;
502+
}
503+
499504
if (hwloc__realloc_infos(infos, 1) < 0)
500505
return -1;
501506

@@ -525,6 +530,12 @@ int hwloc__add_info_nodup(struct hwloc_infos_s *infos,
525530
struct hwloc_info_s *array = infos->array;
526531
unsigned count = infos->count;
527532
unsigned i;
533+
534+
if (!name || !value) {
535+
errno = EINVAL;
536+
return -1;
537+
}
538+
528539
for(i=0; i<count; i++) {
529540
if (!strcmp(array[i].name, name)) {
530541
if (replace) {

include/hwloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,8 @@ hwloc_get_info_by_name(struct hwloc_infos_s *infos, const char *name) __hwloc_at
11621162
*
11631163
* The input strings are copied before being added in the object infos.
11641164
*
1165+
* \p name and \p value must be non \c NULL.
1166+
*
11651167
* \return \c 0 on success, \c -1 on error.
11661168
*
11671169
* \note This function may be used to enforce object colors in the lstopo

0 commit comments

Comments
 (0)