uorb/topics: update delicated match of listener topics

bug: if user input obr_topic is sensor_gps_sate(wrong topic, which does not exist), the using of `strncmp` will assign idx=8 (as sesnor_gps) in the first.

However, there is no match in the `g_sensor_list`, hence idx=8 will give  out value of `sensor_gps` as output(wrong).

Change: This update aims to match the whole value of sensor name in `g_sensor_list`, while keeping `sensor_name+number` match in this condition.

Signed-off-by: haopengxiang <haopengxiang@xiaomi.com>
This commit is contained in:
haopengxiang 2023-07-03 21:58:39 +08:00 committed by Xiang Xiao
parent 6b5038ef7a
commit bdedf648c5

View File

@ -24,6 +24,7 @@
#include <nuttx/config.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
@ -127,14 +128,12 @@ FAR const struct orb_metadata *orb_get_meta(FAR const char *name)
for (i = 0; g_sensor_list[i]; i++)
{
if (!strncmp(g_sensor_list[i]->o_name, name,
strlen(g_sensor_list[i]->o_name)))
{
if (idx == -1 || strlen(g_sensor_list[idx]->o_name) <
strlen(g_sensor_list[i]->o_name))
size_t len = strlen(g_sensor_list[i]->o_name);
if ((!strncmp(g_sensor_list[i]->o_name, name, len))
&& (name[len] == '\0' || isdigit(name[len])))
{
idx = i;
}
break;
}
}