Browse Source

Added assertion on allocation failure for parameter change storage, removed magic numbers

sbg
David Sidrane 10 years ago committed by Lorenz Meier
parent
commit
7950167bc5
  1. 10
      src/modules/systemlib/param/param.c

10
src/modules/systemlib/param/param.c

@ -47,6 +47,7 @@ @@ -47,6 +47,7 @@
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <systemlib/err.h>
@ -115,6 +116,7 @@ get_param_info_count(void) @@ -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) @@ -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) @@ -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;
}

Loading…
Cancel
Save