casaroli commented on code in PR #20748:
URL: https://github.com/apache/nuttx/pull/20748#discussion_r4307019125
##########
libs/libc/regex/regexec.c:
##########
@@ -197,7 +197,8 @@ static reg_errcode_t tre_tnfa_run_parallel(const tre_tnfa_t
*tnfa,
{
/* State variables required by GET_NEXT_WCHAR. */
- tre_char_t prev_c = 0, next_c = 0;
+ tre_char_t prev_c = 0;
+ tre_char_t next_c = 0;
Review Comment:
Done.
##########
libs/libc/regex/regexec.c:
##########
@@ -703,7 +709,8 @@ static reg_errcode_t tre_tnfa_run_backtrack(const
tre_tnfa_t *tnfa,
{
/* State variables required by GET_NEXT_WCHAR. */
- tre_char_t prev_c = 0, next_c = 0;
+ tre_char_t prev_c = 0;
+ tre_char_t next_c = 0;
Review Comment:
Done.
##########
libs/libc/regex/regexec.c:
##########
@@ -55,9 +55,22 @@ static void tre_fill_pmatch(size_t nmatch, regmatch_t
pmatch[], int cflags,
/* from tre-match-utils.h
*/
+/* The input ends at the first NUL byte when len is negative, or after
+ * len bytes otherwise (REG_STARTEND). A NUL byte before the end of the
+ * input is an ordinary character.
+ */
+
+#define AT_EOS() (len < 0 ? next_c == L'\0' : pos >= len)
+
#define GET_NEXT_WCHAR() do { \
prev_c = next_c;pos += pos_add_next; \
- if ((pos_add_next = mbtowc(&next_c, str_byte, MB_LEN_MAX)) <= 0){ \
+ if (len >= 0 && pos >= len) \
+ { \
+ next_c = L'\0'; \
+ pos_add_next = 1; \
+ } \
+ else if ((pos_add_next = mbtowc(&next_c, str_byte, \
+ len < 0 ? MB_LEN_MAX : len - pos)) <= 0){ \
Review Comment:
Done.
##########
libs/libc/regex/regexec.c:
##########
@@ -1250,20 +1296,31 @@ int regexec(const regex_t *restrict preg, const char
*restrict string,
{
/* The regex has back references, use the backtracking matcher. */
- status = tre_tnfa_run_backtrack(tnfa, string, tags, eflags, &eo);
+ status = tre_tnfa_run_backtrack(tnfa, string, len, tags, eflags,
+ &eo);
}
else
{
/* Exact matching, no back references, use the parallel matcher. */
- status = tre_tnfa_run_parallel(tnfa, string, tags, eflags, &eo);
+ status = tre_tnfa_run_parallel(tnfa, string, len, tags, eflags,
+ &eo);
}
if (status == REG_OK)
{
/* A match was found, so fill the submatch registers. */
tre_fill_pmatch(nmatch, pmatch, tnfa->cflags, tnfa, tags, eo);
+
+ for (i = 0; so > 0 && i < nmatch; i++)
+ {
+ if (pmatch[i].rm_so >= 0)
+ {
+ pmatch[i].rm_so += so;
Review Comment:
Done: tre_fill_pmatch() takes the offset now. The back-reference call passes
0, because there the offsets must stay relative to the searched text.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]