tre
tre copied to clipboard
Add distinct error message for maximum number in {} being too large
This PR add a distinct error message for the maximum number in {} being too large (hard-coded to 255 in tre.h).
We recently switched to using tre-regex in Pi-hole and received a report today, that the regex
a{2,256}
was returning
{} content invalid
(return code REG_BADBR).
This was a bit of a mystery at first, as GNU regex doesn't seem to enforce a maximum number of iterations in a bound expression. I propose adding an explicit warning message to help users seeing what is wrong.
The new return code REG_BADMAX has a distinct error message including the upper limit:
Maximum repetition in {} larger than 255
Including the limit here seems meaningful as the limit is set at compile time and not customizable during runtime. Hence, users have no access to its actual value otherwise. I use stringification of the C preprocessor to implement this transparently and without overhead.
I added a test case for the new return type. make check passes.
[I'm not a maintainer here, just a bystander reviewing in hope it helps land PRs faster...]
LGTM :+1: motivation makes sense and the code looks good, FWIW.
About the ISO-8859-1 commit: looks like it undoes an unintentional change from 1st commit, consider squashing to keep history clean.
I've merged this by hand, partly because I've taken a slightly different approach to the string constant encoding/locale in tests/retest.c, and partly because the master branch has moved ahead (via other PRs) since this PR was created. Thanks to both DL6ER (for the PR) and cben (for the review)!
BTW, there seems to be an extra '>' in the new lines for doc/tre-api.html here, I've removed it in the master.