Endless loop in AFL

Discussion in 'App Development' started by hedron, Jun 1, 2015.

  1. hedron

    hedron

    Code:
    for ( i = 1 ; i < BarCount ; i++ ) {
    
    while ( C[i] > O[i] ) {
       upbar = upbar + 1 ;
    }
    }
    Where is the endless loop? It says it's an endless loop, but I just don't see it.

    Thanks.
     
  2. dartmus

    dartmus

    Everytime the condition within the while loop is true, it stays in the while loop, repeating ub=ub+1; It's unable to exit the while loop until the condition becomes false. Only way it will become false is to increment i to i=i+1, which skews the for loop index.

    You could try a different index within the while loop, set it equal to i, then increment your new index to index=index+1; This will enable the while loop to eventually find a condition that's false.

    Logically, there's no reason for the while loop to be combined with a for loop. You should use one or the other. I prefer the for loop because you can say
    if whatever[ i ] then ub=ub+1; // and it will automatically increment i

    or you could use

    i=1;
    while (i<barcount) {
    if (c[ i ] > O [ i ]) {ub=ub+1}
    i=i+1;
    }

    Another factor to consider, double check to make certain uppercase O is not the numeral zero.
     
    Last edited: Jun 1, 2015
    hedron and Baron like this.
  3. hedron

    hedron

    Oh, I see now. Thanks.
     
  4. dartmus

    dartmus

    Most of the endless loop errors occur in while loops. They hardly ever occur in for loops. If there's a reason to stop at an address like i, and check for some condition over more than a single bar, then you can nest a 2nd for loop inside the 1st for loop, by assigning the val of the 1st index to the 2nd index, and using a different letter for the 2nd index. It's easier to do in practice than to describe in theory.
     
    hedron likes this.
  5. M.ST.

    M.ST.

    Why even using loop?
    Simply use cum().

    Code:
    up = Cum( C > O );
     
    hedron likes this.
  6. hedron

    hedron

    Why indeed. Thanks, finally "finished." This stupid thing was giving me a headache.

    Code:
    upbars = IIf ( C != O , Sum ( C > O , BarsSince ( O > C ) ) , 0 ) ;
    downbars = IIf ( C != O , Sum ( O > C , BarsSince ( C > O ) ) , 0 ) ;
    
     
  7. M.ST.

    M.ST.


    Code:
    upbars = Sum ( C > O, BarsSince ( O >= C ) ); 
    downbars = Sum ( O > C, BarsSince ( C >= O ) );
    
     
  8. Sergio77

    Sergio77

    Very nice capability in this software. Kudos to developer.