Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reimplement PCRE2_UNREACHABLE() assertions with a safer approach #490

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/pcre2_auto_possess.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ switch(ptype)
default:
return (PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == negated;
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
break;

case PT_WORD:
Expand All @@ -260,7 +260,7 @@ switch(ptype)
if (c < *p) return !negated;
if (c == *p++) return negated;
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
break;

/* Haven't yet thought these through. */
Expand Down Expand Up @@ -1121,7 +1121,7 @@ for(;;)
if (list[1] == 0) return TRUE;
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}


Expand Down
10 changes: 5 additions & 5 deletions src/pcre2_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5245,7 +5245,7 @@ for (;;)
}
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}


Expand Down Expand Up @@ -8406,7 +8406,7 @@ for (;; pptr++)
} /* End of big switch */
} /* End of big loop */

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}


Expand Down Expand Up @@ -8712,7 +8712,7 @@ for (;;)
pptr++;
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}


Expand Down Expand Up @@ -9400,7 +9400,7 @@ for (;; pptr++)
pptr += meta_extra_lengths[meta];
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}


Expand Down Expand Up @@ -10478,7 +10478,7 @@ if ((options & PCRE2_LITERAL) == 0)
break;

default:
PCRE2_UNREACHABLE();
PCRE2_UNREACHABLE(0);
}
break; /* Out of the table scan loop */
}
Expand Down
3 changes: 2 additions & 1 deletion src/pcre2_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,8 @@ for (i = 0; i < 2; i++)
use_length = *bufflenptr + 1;
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(1); /* Control never reaches here */
return PCRE2_ERROR_INTERNAL;
}


Expand Down
58 changes: 29 additions & 29 deletions src/pcre2_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}

else /* Maximize */
Expand Down Expand Up @@ -1430,7 +1430,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
if (Lc != cc && Loc != cc) RRETURN(MATCH_NOMATCH);
Feptr++;
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}

else /* Maximize */
Expand Down Expand Up @@ -1488,7 +1488,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
}
if (Lc != UCHAR21INCTEST(Feptr)) RRETURN(MATCH_NOMATCH);
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}
else /* Maximize */
{
Expand Down Expand Up @@ -1706,7 +1706,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
Feptr++;
}
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}

/* Maximize case */
Expand Down Expand Up @@ -1844,7 +1844,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
if (Lc == *Feptr++) RRETURN(MATCH_NOMATCH);
}
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}

/* Maximize case */
Expand Down Expand Up @@ -2071,7 +2071,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
}
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}

/* If maximizing, find the longest possible run, then work backwards. */
Expand Down Expand Up @@ -2152,7 +2152,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
}
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

#undef Lbyte_map_address
#undef Lbyte_map
Expand Down Expand Up @@ -2245,7 +2245,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
GETCHARINCTEST(fc, Feptr);
if (!PRIV(xclass)(fc, Lxclass_data, utf)) RRETURN(MATCH_NOMATCH);
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}

/* If maximizing, find the longest possible run, then work backwards. */
Expand Down Expand Up @@ -2288,7 +2288,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}
#endif /* SUPPORT_WIDE_CHARS: end of XCLASS */

Expand Down Expand Up @@ -3532,7 +3532,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
if (Lctype == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_LAMP:
for (;;)
Expand All @@ -3554,7 +3554,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_GC:
for (;;)
Expand All @@ -3572,7 +3572,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_PC:
for (;;)
Expand All @@ -3590,7 +3590,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_SC:
for (;;)
Expand All @@ -3608,7 +3608,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_SCX:
for (;;)
Expand All @@ -3631,7 +3631,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_ALNUM:
for (;;)
Expand All @@ -3651,7 +3651,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

/* Perl space used to exclude VT, but from Perl 5.18 it is included,
which means that Perl space and POSIX space are now identical. PCRE
Expand Down Expand Up @@ -3684,7 +3684,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
}
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_WORD:
for (;;)
Expand All @@ -3708,7 +3708,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_CLIST:
for (;;)
Expand Down Expand Up @@ -3746,7 +3746,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
}
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_UCNC:
for (;;)
Expand All @@ -3766,7 +3766,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_BIDICL:
for (;;)
Expand All @@ -3784,7 +3784,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

case PT_BOOL:
for (;;)
Expand All @@ -3807,7 +3807,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

/* This should never occur */
default:
Expand Down Expand Up @@ -4114,7 +4114,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
}
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}

/* If maximizing, it is worth using inline code for speed, doing the type
Expand Down Expand Up @@ -5126,7 +5126,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
}
Feptr += slength;
}
PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}

/* If maximizing, find the longest string and work backwards, as long as
Expand Down Expand Up @@ -5201,7 +5201,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

#undef Lcaseless
#undef Lmin
Expand Down Expand Up @@ -5426,7 +5426,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
if (*Fecode != OP_ALT) RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

#undef Lframe_type

Expand Down Expand Up @@ -5512,7 +5512,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
if (*Lstart_branch != OP_ALT) RRETURN(MATCH_NOMATCH);
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

#undef Lframe_type
#undef Lstart_branch
Expand Down Expand Up @@ -6024,7 +6024,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
#endif
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */

#undef Lmin
#undef Lmax
Expand Down Expand Up @@ -6622,7 +6622,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,

} /* End of main loop */

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */


/* ========================================================================= */
Expand Down
2 changes: 1 addition & 1 deletion src/pcre2_study.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ for (;;)
}
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
PCRE2_UNREACHABLE(0); /* Control never reaches here */
}


Expand Down
Loading