@@ -108,7 +108,7 @@ void atc_search(atc_t *atc)
108108 for (uint8_t search = 0 ; search < _ATC_SEARCH_MAX ; search ++ )
109109 {
110110 if (atc -> search [search ] == NULL )
111- break ;
111+ continue ;
112112 char * str = strstr ((char * ) atc -> rxBuffer , atc -> search [search ]);
113113 if (str != NULL )
114114 {
@@ -121,10 +121,13 @@ void atc_search(atc_t *atc)
121121char * atc_searchAnswer (atc_t * atc , uint8_t items , uint8_t * foundIndex )
122122{
123123 * foundIndex = 0 ;
124- if (items >= _ATC_SEARCH_CMD_MAX )
125- items = _ATC_SEARCH_CMD_MAX ;
126124 for (uint8_t search = 0 ; search < items ; search ++ )
127125 {
126+ if (search == _ATC_SEARCH_CMD_MAX )
127+ {
128+ atc_printf ("[%s] Error: Search command limit reached" , atc -> name );
129+ break ;
130+ }
128131 if (atc -> searchCmd [search ] == NULL )
129132 break ;
130133 char * str = strstr ((char * ) atc -> rxBuffer , atc -> searchCmd [search ]);
@@ -152,8 +155,11 @@ bool atc_available(atc_t *atc)
152155//####################################################################################################
153156bool atc_addSearch (atc_t * atc , const char * str )
154157{
155- if (atc -> searchIndex == _ATC_SEARCH_MAX - 1 )
158+ if (atc -> searchIndex == _ATC_SEARCH_MAX )
159+ {
160+ atc_printf ("[%s] Error: Search limit reached" , atc -> name );
156161 return false;
162+ }
157163 atc -> search [atc -> searchIndex ] = (char * ) atc_alloc (strlen (str ) + 1 );
158164 if (atc -> search [atc -> searchIndex ] != NULL )
159165 {
@@ -180,15 +186,18 @@ int8_t atc_command(atc_t *atc, const char *command, uint32_t timeout_ms, char *a
180186 va_start (tag , items );
181187 for (uint8_t i = 0 ; i < items ; i ++ )
182188 {
189+ if (i == _ATC_SEARCH_CMD_MAX )
190+ {
191+ atc_printf ("[%s] Error: Search command limit reached" , atc -> name );
192+ break ;
193+ }
183194 char * str = va_arg (tag , char * );
184195 atc -> searchCmd [i ] = (char * ) atc_alloc (strlen (str ) + 1 );
185196 if (atc -> searchCmd [i ] != NULL )
186197 {
187198 strcpy (atc -> searchCmd [i ], str );
188199 atc -> searchCmd [i ][strlen (str )] = 0 ;
189200 }
190- if (items >= _ATC_SEARCH_CMD_MAX )
191- break ;
192201 }
193202 va_end (tag );
194203 atc_transmit (atc , (uint8_t * ) command , strlen (command ));
0 commit comments