]> git.draconx.ca Git - cdecl99.git/commitdiff
Fix bogus switch cases in declgen.
authorNick Bowler <nbowler@draconx.ca>
Sun, 18 Mar 2012 20:54:43 +0000 (16:54 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sun, 18 Mar 2012 21:02:27 +0000 (17:02 -0400)
One of the switch statements in declgen has completely bogus case
labels: '0', '1', ... instead of 0, 1, ...

Fix this up and also add a default: assert(0); which would have caught
this earlier.  Improve the test case output when a randomdecl failure
causes the test to fail.

Also add a comment to the one switch statement in this file which
intentionally does not have a default: assert(0).

test/declgen.c
tests/crossparse-c-random.sh

index 9c774ff6a97ace92499c5020d5f92718c622c640..af7dd8d6c12f625008f2e51e25cdad161ff2f4b2 100644 (file)
@@ -178,6 +178,10 @@ retry:
        case CDECL_TYPE_IDENT:
                assert(!specs->next);
                specs->ident = gen_identifier(rng);
+               break;
+       default:
+               /* Nothing to be done. */
+               ;
        }
 
        return specs;
@@ -274,19 +278,21 @@ static void gen_array(struct gen_rng *rng, struct cdecl_declarator *d)
        d->u.array = (struct cdecl_array){0};
 
        switch (gsl_rng_uniform_int(rng->rng, 4)) {
-       case '0':
+       case 0:
                d->u.array.vla = malloc_nofail(1);
                d->u.array.vla[0] = 0;
                break;
-       case '1':
+       case 1:
                d->u.array.vla = gen_identifier(rng);
                break;
-       case '2':
+       case 2:
                d->u.array.length = 0;
                break;
-       case '3':
+       case 3:
                d->u.array.length = gsl_rng_uniform_int(rng->rng, -1);
                break;
+       default:
+               assert(0);
        }
 }
 
index 9fc45fb4b7d6415028d8b8197fa0e545e6e04815..a800f3f938b065c49029464cdf8277383d212227 100755 (executable)
@@ -72,6 +72,12 @@ eval_cmd=`exec 3>&1
        } | proc >&3`
 eval "$eval_cmd"
 
+if test x"$gen_status" != x"0"; then
+       printf '%s: %s failed with status=%d\n' \
+               "$0" "$randomdecl" "$gen_status" 1>&2
+       exit 1
+fi
+
 expected_count=`expr "$TESTITER" + 0`
 if test x"$count" != x"$expected_count"; then
        printf '%s: failed after %d successful tests (out of %d)\n' \
@@ -79,5 +85,5 @@ if test x"$count" != x"$expected_count"; then
        exit 1
 fi
 
-test x"$result" = x"pass" && test x"$gen_status" = x"0" && exit 0
+test x"$result" = x"pass" && exit 0
 exit 1