Skip to content

Commit

Permalink
fix search limit
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnikita committed Nov 14, 2023
1 parent 810a79f commit b51a25f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions atc.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void atc_search(atc_t *atc)
for (uint8_t search = 0; search < _ATC_SEARCH_MAX; search++)
{
if (atc->search[search] == NULL)
break;
continue;
char *str = strstr((char*) atc->rxBuffer, atc->search[search]);
if (str != NULL)
{
Expand All @@ -118,10 +118,13 @@ void atc_search(atc_t *atc)
char* atc_searchAnswer(atc_t *atc, uint8_t items, uint8_t *foundIndex)
{
*foundIndex = 0;
if (items >= _ATC_SEARCH_CMD_MAX)
items = _ATC_SEARCH_CMD_MAX;
for (uint8_t search = 0; search < items; search++)
{
if (search == _ATC_SEARCH_CMD_MAX)
{
atc_printf("[%s] Error: Search command limit reached", atc->name);
break;
}
if (atc->searchCmd[search] == NULL)
break;
char *str = strstr((char*) atc->rxBuffer, atc->searchCmd[search]);
Expand Down Expand Up @@ -149,8 +152,11 @@ bool atc_available(atc_t *atc)
//####################################################################################################
bool atc_addSearch(atc_t *atc, const char *str)
{
if (atc->searchIndex == _ATC_SEARCH_MAX - 1)
if (atc->searchIndex == _ATC_SEARCH_MAX)
{
atc_printf("[%s] Error: Search limit reached", atc->name);
return false;
}
atc->search[atc->searchIndex] = (char*) atc_alloc(strlen(str) + 1);
if (atc->search[atc->searchIndex] != NULL)
{
Expand All @@ -177,15 +183,18 @@ int8_t atc_command(atc_t *atc, const char *command, uint32_t timeout_ms, char *a
va_start(tag, items);
for (uint8_t i = 0; i < items; i++)
{
if (i == _ATC_SEARCH_CMD_MAX)
{
atc_printf("[%s] Error: Search command limit reached", atc->name);
break;
}
char *str = va_arg(tag, char*);
atc->searchCmd[i] = (char*) atc_alloc(strlen(str) + 1);
if (atc->searchCmd[i] != NULL)
{
strcpy(atc->searchCmd[i], str);
atc->searchCmd[i][strlen(str)] = 0;
}
if (items >= _ATC_SEARCH_CMD_MAX)
break;
}
va_end(tag);
atc_transmit(atc, (uint8_t*) command, strlen(command));
Expand Down

0 comments on commit b51a25f

Please sign in to comment.