From 7950167bc5465bed5383d100db5ebd8f8f3f4b95 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 18 May 2015 13:51:21 -1000 Subject: [PATCH] Added assertion on allocation failure for parameter change storage, removed magic numbers --- src/modules/systemlib/param/param.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c index 2c64e32f17..47c3814edd 100644 --- a/src/modules/systemlib/param/param.c +++ b/src/modules/systemlib/param/param.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -115,6 +116,7 @@ get_param_info_count(void) if (!param_changed_storage) { size_param_changed_storage_bytes = (param_info_count / bits_per_allocation_unit) + 1; param_changed_storage = calloc(size_param_changed_storage_bytes, 1); + ASSERT(param_changed_storage); } return param_info_count; @@ -316,14 +318,14 @@ param_for_used_index(unsigned index) int count = 0; for (unsigned i = 0; i < (unsigned)size_param_changed_storage_bytes; i++) { - for (unsigned j = 0; j < 8; j++) { + for (unsigned j = 0; j < bits_per_allocation_unit; j++) { if (param_changed_storage[i] & (1 << j)) { /* we found the right used count, * return the param value */ if (index == count) { - return (param_t)(i * 8 + j); + return (param_t)(i * bits_per_allocation_unit + j); } count++; @@ -357,10 +359,10 @@ param_get_used_index(param_t param) int count = 0; for (unsigned i = 0; i < (unsigned)size_param_changed_storage_bytes; i++) { - for (unsigned j = 0; j < 8; j++) { + for (unsigned j = 0; j < bits_per_allocation_unit; j++) { if (param_changed_storage[i] & (1 << j)) { - if ((unsigned)param == i * 8 + j) { + if ((unsigned)param == i * bits_per_allocation_unit + j) { return count; }