Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177585254
D57528.1794800792.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D57528.1794800792.diff
View Options
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -500,7 +500,6 @@
procline(struct parsec *pc)
{
regmatch_t pmatch, lastmatch, chkmatch;
- wchar_t wbegin, wend;
size_t st, nst;
unsigned int i;
int r = 0, leflags = eflags;
@@ -566,19 +565,63 @@
continue;
/* Check for whole word match */
if (wflag) {
- wbegin = wend = L' ';
- if (pmatch.rm_so != 0 &&
- sscanf(&pc->ln.dat[pmatch.rm_so - 1],
- "%lc", &wbegin) != 1)
- r = REG_NOMATCH;
- else if ((size_t)pmatch.rm_eo !=
- pc->ln.len &&
- sscanf(&pc->ln.dat[pmatch.rm_eo],
- "%lc", &wend) != 1)
- r = REG_NOMATCH;
- else if (iswword(wbegin) ||
- iswword(wend))
- r = REG_NOMATCH;
+ if (pmatch.rm_so != 0) {
+ unsigned char ch =
+ (unsigned char)pc->
+ ln.dat[pmatch.rm_so - 1];
+ if (ch < 0x80) {
+ if (isalnum(ch) || ch == '_')
+ r = REG_NOMATCH;
+ } else if ((ch & 0xC0) == 0x80) {
+ /* Continuation byte: part of a word */
+ r = REG_NOMATCH;
+ } else {
+ mbstate_t mbstate;
+ wchar_t wc;
+ size_t n;
+
+ memset(&mbstate, 0,
+ sizeof(mbstate));
+ n = mbrtowc(&wc,
+ &pc->ln.dat[
+ pmatch.rm_so - 1],
+ MB_CUR_MAX,
+ &mbstate);
+ if (n == (size_t)-1 ||
+ n == (size_t)-2 ||
+ iswword(wc))
+ r = REG_NOMATCH;
+ }
+ }
+ if (r == 0 && (size_t)pmatch.rm_eo !=
+ pc->ln.len) {
+ unsigned char ch =
+ (unsigned char)pc->
+ ln.dat[pmatch.rm_eo];
+ if (ch < 0x80) {
+ if (isalnum(ch) || ch == '_')
+ r = REG_NOMATCH;
+ } else if ((ch & 0xC0) == 0x80) {
+ /* Continuation byte: part of a word */
+ r = REG_NOMATCH;
+ } else {
+ mbstate_t mbstate;
+ wchar_t wc;
+ size_t n;
+
+ memset(&mbstate, 0,
+ sizeof(mbstate));
+ n = mbrtowc(&wc,
+ &pc->ln.dat[
+ pmatch.rm_eo],
+ MB_CUR_MAX,
+ &mbstate);
+ if (n == (size_t)-1 ||
+ n == (size_t)-2 ||
+ iswword(wc))
+ r = REG_NOMATCH;
+ }
+ }
/*
* If we're doing whole word matching and we
* matched once, then we should try the pattern
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 16, 3:46 AM (22 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41758416
Default Alt Text
D57528.1794800792.diff (2 KB)
Attached To
Mode
D57528: grep(1): optimize -w/--word-regexp word boundary check
Attached
Detach File
Event Timeline