• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/99_bugs/58_for_loop_condition_at_function_start

  1 A counting for loop without an initializer that opened a function body
  2 placed its condition at bytecode offset 0, which the compiler mistook
  3 for an absent condition. The loop then never jumped back to the test
  4 and kept running after the condition had turned false.
  5 
  6 -- Testcase --
  7 {%
  8         function count_down(n) {
  9                 for (; n > 0; n--) {
 10                         if (n < -2)
 11                                 return "runaway";
 12 
 13                         print(n, "\n");
 14                 }
 15 
 16                 return "done";
 17         }
 18 
 19         function walk(n) {
 20                 for (; n > 1; n = int(n / 2))
 21                         if (n == 0)
 22                                 return "runaway";
 23 
 24                 return n;
 25         }
 26 
 27         print(count_down(3), "\n");
 28         print(walk(8), "\n");
 29 %}
 30 -- End --
 31 
 32 -- Expect stdout --
 33 3
 34 2
 35 1
 36 done
 37 1
 38 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt