regexec.c: regrepeat() change default: handling
authorKarl Williamson <public@khwilliamson.com>
Fri, 19 Oct 2012 17:57:16 +0000 (11:57 -0600)
committerKarl Williamson <public@khwilliamson.com>
Fri, 19 Oct 2012 18:20:22 +0000 (12:20 -0600)
The core of this function is a large switch() statement.  Prior to this
commit, the default: case of it assumed that this meant that the
node-type was a zero-length node.  It is safer to explicitly mention
all the cases you expect to handle, and have the default fail so that
you know sooner that you forgot to handle a situation.  That is how all
other switch statements in this file are set up, and now this one is
too.

I added cases for all the node types in regcomp.c that are SIMPLE, and
hence could conceivably be handled by regrepeat(), and changed the
default: case to croak.

I considered doing an #ifdef DEBUGGING around this, but no other
switches() in the file do so, so I followed that paradigm.

regexec.c

index fe5dfab..f01b605 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -7157,8 +7157,27 @@ S_regrepeat(pTHX_ const regexp *prog, char **startposp, const regnode *p, I32 ma
        }       
        break;
 
-    default:           /* Called on something of 0 width. */
-       break;          /* So match right here or not at all. */
+    case BOUND:
+    case BOUNDA:
+    case BOUNDL:
+    case BOUNDU:
+    case EOS:
+    case GPOS:
+    case KEEPS:
+    case NBOUND:
+    case NBOUNDA:
+    case NBOUNDL:
+    case NBOUNDU:
+    case OPFAIL:
+    case SBOL:
+    case SEOL:
+        /* These are all 0 width, so match right here or not at all. */
+        break;
+
+    default:
+        Perl_croak(aTHX_ "panic: regrepeat() called with unrecognized node type %d='%s'", OP(p), PL_reg_name[OP(p)]);
+        assert(0); /* NOTREACHED */
+
     }
 
     if (hardcount)