@@ -2992,6 +2992,7 @@ if ((options & PCRE2_LITERAL) != 0)
29922992 {
29932993 if (parsed_pattern >= parsed_pattern_end )
29942994 {
2995+ PCRE2_DEBUG_UNREACHABLE ();
29952996 errorcode = ERR63 ; /* Internal error (parsed pattern overflow) */
29962997 goto FAILED ;
29972998 }
@@ -3064,6 +3065,7 @@ while (ptr < ptrend)
30643065 {
30653066 /* Weak pre-write check; only ensures parsed_pattern[0] is writeable
30663067 (but the code below can write many chars). Better than nothing. */
3068+ PCRE2_DEBUG_UNREACHABLE ();
30673069 errorcode = ERR63 ; /* Internal error (parsed pattern overflow) */
30683070 goto FAILED ;
30693071 }
@@ -4562,6 +4564,7 @@ while (ptr < ptrend)
45624564 switch (meta )
45634565 {
45644566 default :
4567+ PCRE2_DEBUG_UNREACHABLE ();
45654568 errorcode = ERR89 ; /* Unknown code; should never occur because */
45664569 goto FAILED ; /* the meta values come from a table above. */
45674570
@@ -5687,6 +5690,7 @@ Otherwise we have unclosed parentheses. */
56875690
56885691if (parsed_pattern >= parsed_pattern_end )
56895692 {
5693+ PCRE2_DEBUG_UNREACHABLE ();
56905694 errorcode = ERR63 ; /* Internal error (parsed pattern overflow) */
56915695 goto FAILED ;
56925696 }
@@ -6006,8 +6010,13 @@ for (;; pptr++)
60066010 if (code > cb -> start_workspace + cb -> workspace_size -
60076011 WORK_SIZE_SAFETY_MARGIN ) /* Check for overrun */
60086012 {
6009- * errorcodeptr = (code >= cb -> start_workspace + cb -> workspace_size )?
6010- ERR52 : ERR86 ;
6013+ if (code >= cb -> start_workspace + cb -> workspace_size )
6014+ {
6015+ PCRE2_DEBUG_UNREACHABLE ();
6016+ * errorcodeptr = ERR52 ; /* Over-ran workspace - internal error */
6017+ }
6018+ else
6019+ * errorcodeptr = ERR86 ;
60116020 return 0 ;
60126021 }
60136022
@@ -7223,15 +7232,6 @@ for (;; pptr++)
72237232 }
72247233 break ;
72257234
7226- /* The ways in which OP_FAIL can be generated, that is by (*FAIL) or
7227- (?!), disallow a quantifier at parse time. We ought to be able to ignore this. */
7228-
7229- case OP_FAIL :
7230- /* TODO: [EC] https://github.com/PCRE2Project/pcre2/issues/541
7231- Should this be removed, now that '[]' has been changed so it doesn't produce OP_FAIL? */
7232- PCRE2_UNREACHABLE ();
7233- goto END_REPEAT ;
7234-
72357235 /* Prior to 10.30, repeated recursions were wrapped in OP_ONCE brackets
72367236 because pcre2_match() could not handle backtracking into recursively
72377237 called groups. Now that this backtracking is available, we no longer need
@@ -7640,9 +7640,10 @@ for (;; pptr++)
76407640 here because it just makes it horribly messy. */
76417641
76427642 default :
7643- if (op_previous >= OP_EODN ) /* Not a character type - internal error */
7643+ if (op_previous >= OP_EODN || op_previous <= OP_WORD_BOUNDARY )
76447644 {
7645- * errorcodeptr = ERR10 ;
7645+ PCRE2_DEBUG_UNREACHABLE ();
7646+ * errorcodeptr = ERR10 ; /* Not a character type - internal error */
76467647 return 0 ;
76477648 }
76487649 else
@@ -8112,9 +8113,7 @@ for (;; pptr++)
81128113 default :
81138114 if (meta >= META_END )
81148115 {
8115- #ifdef DEBUG_SHOW_PARSED
8116- fprintf (stderr , "** Unrecognized parsed pattern item 0x%.8x\n" , * pptr );
8117- #endif
8116+ PCRE2_DEBUG_UNREACHABLE ();
81188117 * errorcodeptr = ERR89 ; /* Internal error - unrecognized. */
81198118 return 0 ;
81208119 }
@@ -9753,7 +9752,8 @@ for (;; pptr++)
97539752return branchlength ;
97549753
97559754PARSED_SKIP_FAILED :
9756- * errcodeptr = ERR90 ;
9755+ PCRE2_DEBUG_UNREACHABLE ();
9756+ * errcodeptr = ERR90 ; /* Unhandled META code - internal error */
97579757return -1 ;
97589758}
97599759
@@ -9896,6 +9896,7 @@ for (; *pptr != META_END; pptr++)
98969896 be avoided by providing a proper implementation for all supported cases
98979897 below. */
98989898
9899+ PCRE2_DEBUG_UNREACHABLE ();
98999900 cb -> erroroffset = 0 ;
99009901 return ERR70 ; /* Unrecognized meta code */
99019902
@@ -10467,6 +10468,7 @@ switch(newline)
1046710468 break ;
1046810469
1046910470 default :
10471+ PCRE2_DEBUG_UNREACHABLE ();
1047010472 errorcode = ERR56 ;
1047110473 goto HAD_EARLY_ERROR ;
1047210474 }
@@ -10540,13 +10542,7 @@ if (has_lookbehind)
1054010542 }
1054110543 memset (cb .groupinfo , 0 , (2 * cb .bracount + 1 ) * sizeof (uint32_t ));
1054210544 errorcode = check_lookbehinds (cb .parsed_pattern , NULL , NULL , & cb , & loopcount );
10543- if (errorcode != 0 )
10544- {
10545- /* BUG: check_lookbehinds() is missing code for a valid META */
10546- PCRE2_ASSERT (errorcode != ERR70 );
10547-
10548- goto HAD_CB_ERROR ;
10549- }
10545+ if (errorcode != 0 ) goto HAD_CB_ERROR ;
1055010546 }
1055110547
1055210548/* For debugging, there is a function that shows the parsed pattern vector. */
@@ -10738,7 +10734,12 @@ memory as unaddressable, so that any out-of-bound reads can be detected. */
1073810734
1073910735* code ++ = OP_END ;
1074010736usedlength = code - codestart ;
10741- if (usedlength > length ) errorcode = ERR23 ; else
10737+ if (usedlength > length )
10738+ {
10739+ PCRE2_DEBUG_UNREACHABLE ();
10740+ errorcode = ERR23 ; /* Overflow of code block - internal error */
10741+ }
10742+ else
1074210743 {
1074310744 re -> blocksize -= CU2BYTES (length - usedlength );
1074410745#ifdef SUPPORT_VALGRIND
@@ -10791,6 +10792,7 @@ if (errorcode == 0 && cb.had_recurse)
1079110792 rgroup = PRIV (find_bracket )(search_from , utf , groupnumber );
1079210793 if (rgroup == NULL )
1079310794 {
10795+ PCRE2_DEBUG_UNREACHABLE ();
1079410796 errorcode = ERR53 ;
1079510797 break ;
1079610798 }
@@ -10823,7 +10825,11 @@ function call. */
1082310825if (errorcode == 0 && (optim_flags & PCRE2_OPTIM_AUTO_POSSESS ) != 0 )
1082410826 {
1082510827 PCRE2_UCHAR * temp = (PCRE2_UCHAR * )codestart ;
10826- if (PRIV (auto_possessify )(temp , & cb ) != 0 ) errorcode = ERR80 ;
10828+ if (PRIV (auto_possessify )(temp , & cb ) != 0 )
10829+ {
10830+ PCRE2_DEBUG_UNREACHABLE ();
10831+ errorcode = ERR80 ;
10832+ }
1082710833 }
1082810834
1082910835/* Failed to compile, or error while post-processing. */
@@ -10978,6 +10984,7 @@ if ((optim_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0)
1097810984
1097910985 if (PRIV (study )(re ) != 0 )
1098010986 {
10987+ PCRE2_DEBUG_UNREACHABLE ();
1098110988 errorcode = ERR31 ;
1098210989 goto HAD_CB_ERROR ;
1098310990 }
0 commit comments