forked from Archive/PX4-Autopilot
param: Fix an off by 1 issue and some style fixes.
This commit is contained in:
parent
fe8deeeed9
commit
bf57e86dc2
|
@ -263,25 +263,30 @@ param_find_internal(const char *name, bool notification)
|
|||
{
|
||||
param_t middle;
|
||||
param_t front = 0;
|
||||
param_t last = get_param_info_count()-1;
|
||||
param_t last = get_param_info_count() - 1;
|
||||
|
||||
/* perform a binary search of the known parameters */
|
||||
|
||||
while (front <= last) {
|
||||
middle = front + (last-front) / 2;
|
||||
middle = front + (last - front) / 2;
|
||||
int ret = strcmp(name, param_info_base[middle].name);
|
||||
|
||||
if (ret == 0) {
|
||||
if (notification) {
|
||||
param_set_used_internal(middle);
|
||||
}
|
||||
|
||||
return middle;
|
||||
|
||||
} else if (middle == front || middle == last) {
|
||||
/* An end point has been hit, but there has been no match */
|
||||
break;
|
||||
|
||||
} else if (ret < 0) {
|
||||
last = middle - 1;
|
||||
|
||||
} else {
|
||||
front = middle + 1;
|
||||
front = middle;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -216,6 +216,7 @@ param_main(int argc, char *argv[])
|
|||
if (!strcmp(argv[1], "find")) {
|
||||
if (argc >= 3) {
|
||||
return do_find(argv[2]);
|
||||
|
||||
} else {
|
||||
warnx("not enough arguments.\nTry 'param find PARAM_NAME'");
|
||||
return 1;
|
||||
|
@ -341,13 +342,15 @@ do_show(const char *search_string)
|
|||
}
|
||||
|
||||
static int
|
||||
do_find(const char* name)
|
||||
do_find(const char *name)
|
||||
{
|
||||
param_t ret = param_find_no_notification(name);
|
||||
|
||||
if (ret == PARAM_INVALID) {
|
||||
warnx("Parameter %s not found", name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Found param %s at index %d\n", name, ret);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue