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

Sources/ucode/tests/custom/99_bugs/11_switch_stack_mismatch

  1 When jumping into a case following prior cases declaring local variables,
  2 the preceding local variable declarations were skipped, leading to an
  3 unexpected stack layout which caused local variables to carry wrong
  4 values at run time and eventual segmentation faults when attempting to
  5 unwind the stack on leaving the lexical switch scope.
  6 
  7 -- Expect stdout --
  8 Matching 1:
  9  - 1: [ null, null, 3, 4 ]
 10  - 2: [ null, null, 3, 4, 5, 6 ]
 11 Matching 2:
 12  - 2: [ null, null, null, null, 5, 6 ]
 13 Matching 3:
 14  - default: [ 1, 2 ]
 15  - 1: [ 1, 2, 3, 4 ]
 16  - 2: [ 1, 2, 3, 4, 5, 6 ]
 17 -- End --
 18 
 19 -- Testcase --
 20 {%
 21         for (let n in [1, 2, 3]) {
 22                 printf("Matching %d:\n", n);
 23 
 24                 switch (n) {
 25                         default:
 26                                 let x = 1, y = 2;
 27                                 print(" - default: ", [x, y], "\n");
 28 
 29                         case 1:
 30                                 let a = 3, b = 4;
 31                                 print(" - 1: ", [x, y, a, b], "\n");
 32 
 33                         case 2:
 34                                 let c = 5, d = 6;
 35                                 print(" - 2: ", [x, y, a, b, c, d], "\n");
 36                 }
 37         }
 38 %}
 39 -- End --
 40 
 41 -- Expect stdout --
 42 Matching 1:
 43 Matching 2:
 44  - 2: [ 3, 4 ]
 45  - 3: [ 3, 4, 5, 6 ]
 46 Matching 3:
 47  - 3: [ null, null, 5, 6 ]
 48 -- End --
 49 
 50 -- Testcase --
 51 {%
 52         for (let n in [1, 2, 3]) {
 53                 printf("Matching %d:\n", n);
 54 
 55                 switch (n) {
 56                         case 2:
 57                                 let a = 3, b = 4;
 58                                 print(" - 2: ", [a, b], "\n");
 59 
 60                         case 3:
 61                                 let c = 5, d = 6;
 62                                 print(" - 3: ", [a, b, c, d], "\n");
 63                 }
 64         }
 65 %}
 66 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt