@@ -105,7 +105,7 @@ void atc_search(atc_t *atc)
105105 for (uint8_t search = 0 ; search < _ATC_SEARCH_MAX ; search ++ )
106106 {
107107 if (atc -> search [search ] == NULL )
108- break ;
108+ continue ;
109109 char * str = strstr ((char * ) atc -> rxBuffer , atc -> search [search ]);
110110 if (str != NULL )
111111 {
@@ -118,10 +118,13 @@ void atc_search(atc_t *atc)
118118char * atc_searchAnswer (atc_t * atc , uint8_t items , uint8_t * foundIndex )
119119{
120120 * foundIndex = 0 ;
121- if (items >= _ATC_SEARCH_CMD_MAX )
122- items = _ATC_SEARCH_CMD_MAX ;
123121 for (uint8_t search = 0 ; search < items ; search ++ )
124122 {
123+ if (search == _ATC_SEARCH_CMD_MAX )
124+ {
125+ atc_printf ("[%s] Error: Search command limit reached" , atc -> name );
126+ break ;
127+ }
125128 if (atc -> searchCmd [search ] == NULL )
126129 break ;
127130 char * str = strstr ((char * ) atc -> rxBuffer , atc -> searchCmd [search ]);
@@ -149,8 +152,11 @@ bool atc_available(atc_t *atc)
149152//####################################################################################################
150153bool atc_addSearch (atc_t * atc , const char * str )
151154{
152- if (atc -> searchIndex == _ATC_SEARCH_MAX - 1 )
155+ if (atc -> searchIndex == _ATC_SEARCH_MAX )
156+ {
157+ atc_printf ("[%s] Error: Search limit reached" , atc -> name );
153158 return false;
159+ }
154160 atc -> search [atc -> searchIndex ] = (char * ) atc_alloc (strlen (str ) + 1 );
155161 if (atc -> search [atc -> searchIndex ] != NULL )
156162 {
@@ -177,15 +183,18 @@ int8_t atc_command(atc_t *atc, const char *command, uint32_t timeout_ms, char *a
177183 va_start (tag , items );
178184 for (uint8_t i = 0 ; i < items ; i ++ )
179185 {
186+ if (i == _ATC_SEARCH_CMD_MAX )
187+ {
188+ atc_printf ("[%s] Error: Search command limit reached" , atc -> name );
189+ break ;
190+ }
180191 char * str = va_arg (tag , char * );
181192 atc -> searchCmd [i ] = (char * ) atc_alloc (strlen (str ) + 1 );
182193 if (atc -> searchCmd [i ] != NULL )
183194 {
184195 strcpy (atc -> searchCmd [i ], str );
185196 atc -> searchCmd [i ][strlen (str )] = 0 ;
186197 }
187- if (items >= _ATC_SEARCH_CMD_MAX )
188- break ;
189198 }
190199 va_end (tag );
191200 atc_transmit (atc , (uint8_t * ) command , strlen (command ));
0 commit comments