!34 [grep]backport patch from upstream

From: @gaoruoshu 
Reviewed-by: @hubin95 
Signed-off-by: @hubin95
This commit is contained in:
openeuler-ci-bot 2022-12-27 07:43:17 +00:00 committed by Gitee
commit 66c4c3f57c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,67 @@
From b061d24916fb9a14da37a3f2a05cb80dc65cfd38 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 5 Dec 2022 14:16:45 -0800
Subject: [PATCH] backport: grep: bug backref in last of multiple patterns
---
src/dfasearch.c | 25 ++++++++++++-------------
tests/backref | 8 ++++++++
2 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/src/dfasearch.c b/src/dfasearch.c
index d6afa8d..2d0e861 100644
--- a/src/dfasearch.c
+++ b/src/dfasearch.c
@@ -267,20 +267,19 @@ GEAcompile (char *pattern, size_t size, reg_syntax_t syntax_bits,
if (compilation_failed)
exit (EXIT_TROUBLE);
- if (prev <= patlim)
+ if (patlim < prev)
+ buflen--;
+ else if (pattern < prev)
{
- if (pattern < prev)
- {
- ptrdiff_t prevlen = patlim - prev;
- buf = xrealloc (buf, buflen + prevlen);
- memcpy (buf + buflen, prev, prevlen);
- buflen += prevlen;
- }
- else
- {
- buf = pattern;
- buflen = size;
- }
+ ptrdiff_t prevlen = patlim - prev;
+ buf = xrealloc (buf, buflen + prevlen);
+ memcpy (buf + buflen, prev, prevlen);
+ buflen += prevlen;
+ }
+ else
+ {
+ buf = pattern;
+ buflen = size;
}
/* In the match_words and match_lines cases, we use a different pattern
diff --git a/tests/backref b/tests/backref
index 947981b..5cc3060 100755
--- a/tests/backref
+++ b/tests/backref
@@ -43,4 +43,12 @@ if test $? -ne 2 ; then
failures=1
fi
+# https://bugs.gnu.org/36148#13
+echo 'Total failed: 2 (1 ignored)' |
+ grep -e '^Total failed: 0$' -e '^Total failed: \([0-9]*\) (\1 ignored)$'
+if test $? -ne 1 ; then
+ echo "Backref: Multiple -e test, test #5 failed"
+ failures=1
+fi
+
Exit $failures
--
2.30.1 (Apple Git-130)

View File

@ -1,6 +1,6 @@
Name: grep
Version: 3.7
Release: 7
Release: 8
Summary: A string search utility
License: GPLv3+
URL: http://www.gnu.org/software/grep/
@ -22,6 +22,7 @@ Patch10: backport-grep-fix-bug-with-and-some-Hangul-Syllables.patch
Patch11: backport-tests-improve-tests-of.patch
Patch12: backport-grep-sanity-check-GREP_COLOR.patch
Patch13: backport-grep-fix-regex-compilation-memory-leaks.patch
Patch14: backport-grep-bug-backref-in-last-of-multiple-patter.patch
BuildRequires: gcc pcre2-devel texinfo gettext libsigsegv-devel automake
Provides: /bin/egrep /bin/fgrep /bin/grep bundled(gnulib)
@ -67,6 +68,9 @@ make check
%changelog
* Mon Dec 26 2022 gaoruoshu <gaoruoshu@huawei.com> - 3.7-8
- backport patch from upstream
* Wed Jul 27 2022 panxiaohe <panxh.life@foxmail.com> - 3.7-7
- backport patches from upstream