Skip to content

Commit

Permalink
Add some assertions to silence static analysis tools
Browse files Browse the repository at this point in the history
Thanks to Jonathan Peyton for the patch

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
(cherry picked from commit 93f20fc)
  • Loading branch information
bgoglin committed Dec 6, 2019
1 parent 20c6cce commit 0da4f0a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions hwloc/topology-synthetic.c
Expand Up @@ -1503,6 +1503,7 @@ hwloc_topology_export_synthetic(struct hwloc_topology * topology,
signed pdepth;

node = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0);
assert(node);
assert(hwloc__obj_type_is_normal(node->parent->type)); /* only depth-1 memory children for now */
pdepth = node->parent->depth;

Expand Down
5 changes: 5 additions & 0 deletions hwloc/topology-xml.c
Expand Up @@ -426,6 +426,7 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology,
memory->page_types = malloc(sizeof(*memory->page_types));
memory->page_types_len = 1;
}
assert(memory->page_types);
memory->page_types[0].size = lvalue << 10;
} else if (hwloc__xml_verbose()) {
fprintf(stderr, "%s: ignoring huge_page_size_kB attribute for non-NUMAnode non-root object\n",
Expand All @@ -440,6 +441,7 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology,
memory->page_types = malloc(sizeof(*memory->page_types));
memory->page_types_len = 1;
}
assert(memory->page_types);
memory->page_types[0].count = lvalue;
} else if (hwloc__xml_verbose()) {
fprintf(stderr, "%s: ignoring huge_page_free attribute for non-NUMAnode non-root object\n",
Expand Down Expand Up @@ -1778,6 +1780,8 @@ hwloc_look_xml(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
if (nbobjs == data->nbnumanodes) {
hwloc_obj_t *objs = malloc(nbobjs*sizeof(hwloc_obj_t));
uint64_t *values = malloc(nbobjs*nbobjs*sizeof(*values));
assert(data->nbnumanodes > 0); /* v1dist->nbobjs is >0 after import */
assert(data->first_numanode);
if (objs && values) {
hwloc_obj_t node;
unsigned i;
Expand Down Expand Up @@ -2921,6 +2925,7 @@ hwloc_export_obj_userdata(void *reserved,
int encoded;
size_t encoded_length;
const char *realname;
assert(name);
if (!strncmp(name, "base64", 6)) {
encoded = 1;
encoded_length = BASE64_ENCODED_LENGTH(length);
Expand Down
2 changes: 2 additions & 0 deletions hwloc/topology.c
Expand Up @@ -4113,6 +4113,7 @@ hwloc_topology_restrict(struct hwloc_topology *topology, hwloc_const_bitmap_t se
/* cpuset to clear */
if (flags & HWLOC_RESTRICT_FLAG_REMOVE_MEMLESS) {
hwloc_obj_t pu = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0);
assert(pu);
do {
/* PU will be removed if cpuset gets or was empty */
if (hwloc_bitmap_iszero(pu->cpuset)
Expand Down Expand Up @@ -4148,6 +4149,7 @@ hwloc_topology_restrict(struct hwloc_topology *topology, hwloc_const_bitmap_t se
/* nodeset to clear */
if (flags & HWLOC_RESTRICT_FLAG_REMOVE_CPULESS) {
hwloc_obj_t node = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0);
assert(node);
do {
/* node will be removed if nodeset gets or was empty */
if (hwloc_bitmap_iszero(node->cpuset)
Expand Down

0 comments on commit 0da4f0a

Please sign in to comment.