Skip to content

Conversation

@NWilson
Copy link
Member

@NWilson NWilson commented Dec 2, 2024

One switch case in pcre2_compile.c is not covered by any tests (the ERR7 default).

Add tests covering all the possible escapes, and fix a couple that weren't working (ESC_k and ESC_ub).

Also fix some empty statements causing coverage failures in pcre2_match.c.

Comment on lines +571 to +576
#define RMATCH(ra,rb) \
do { \
start_ecode = ra; \
Freturn_id = rb; \
goto MATCH_RECURSE; \
L_##rb:; \
} \
while (0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the calling code for the macros like RMATCH(...); uses a trailing semicolon.

The existing code was creating a block, not an expression, so the trailing semicolon was treated as a (harmless) empty statement. However, it was polluting the coverage statistics with unreached code lines, because those statements were never reached.

Using a do {...} while (0) is a good way to avoid surprises with macros.

@NWilson NWilson force-pushed the user/niwilson/class-escape-coverage branch from 79cac06 to 6297dd3 Compare December 4, 2024 17:35
/* All others are not allowed in a class */

default:
PCRE2_DEBUG_UNREACHABLE();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not allowed or not possible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not possible (as far as I can tell). I have gone through check_escape() and made a list of every ESC_ code it can return (when passed inclass=TRUE), and added a case statement and a test for all of those. There should be no other escapes allowed, so I added a catch-all default which only triggers in Debug builds.

Copy link
Collaborator

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zherczeg zherczeg merged commit 94a0118 into PCRE2Project:master Dec 6, 2024
21 checks passed
@NWilson NWilson deleted the user/niwilson/class-escape-coverage branch December 17, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants