@@ -254,11 +254,12 @@ String Stream::readStringUntil(char terminator)
254254int Stream::findMulti ( struct Stream ::MultiTarget *targets, int tCount) {
255255 // any zero length target string automatically matches and would make
256256 // a mess of the rest of the algorithm.
257- for (struct MultiTarget *t = targets; t < targets+tCount; ++t)
257+ for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
258258 if (t->len <= 0 )
259259 return t - targets;
260+ }
260261
261- while (1 ) {
262+ while (1 ) {
262263 int c = timedRead ();
263264 if (c < 0 )
264265 return -1 ;
@@ -277,37 +278,40 @@ int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
277278 // but it will match the second position so we can't just reset the current
278279 // index to 0 when we find a mismatch.
279280 if (t->index == 0 )
280- continue ;
281+ continue ;
281282
282283 int origIndex = t->index ;
283284 do {
284- --t->index ;
285- // first check if current char works against the new current index
286- if (c != t->str [t->index ])
287- continue ;
288-
289- // if it's the only char then we're good, nothing more to check
290- if (t->index == 0 ) {
291- t->index ++;
292- break ;
293- }
294-
295- // otherwise we need to check the rest of the found string
296- int diff = origIndex - t->index ;
297- size_t i;
298- for (i = 0 ; i < t->index ; ++i)
299- if (t->str [i] != t->str [i + diff])
300- break ;
301- // if we successfully got through the previous loop then our current
302- // index is good.
303- if (i == t->index ) {
304- t->index ++;
305- break ;
306- }
307- // otherwise we just try the next index
285+ --t->index ;
286+ // first check if current char works against the new current index
287+ if (c != t->str [t->index ])
288+ continue ;
289+
290+ // if it's the only char then we're good, nothing more to check
291+ if (t->index == 0 ) {
292+ t->index ++;
293+ break ;
294+ }
295+
296+ // otherwise we need to check the rest of the found string
297+ int diff = origIndex - t->index ;
298+ size_t i;
299+ for (i = 0 ; i < t->index ; ++i) {
300+ if (t->str [i] != t->str [i + diff])
301+ break ;
302+ }
303+
304+ // if we successfully got through the previous loop then our current
305+ // index is good.
306+ if (i == t->index ) {
307+ t->index ++;
308+ break ;
309+ }
310+
311+ // otherwise we just try the next index
308312 } while (t->index );
309313 }
310314 }
311315 // unreachable
312316 return -1 ;
313- }
317+ }
0 commit comments