Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151647227
D10098.id27039.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D10098.id27039.diff
View Options
Index: usr.bin/grep/regex/tre-fastmatch.c
===================================================================
--- usr.bin/grep/regex/tre-fastmatch.c
+++ usr.bin/grep/regex/tre-fastmatch.c
@@ -98,6 +98,18 @@
fg->pattern[siz] = '\0'; \
} \
+#define CONV_MBS_PAT(src, dest, destsz) \
+ { \
+ destsz = wcstombs(NULL, src, 0); \
+ if (destsz == (size_t)-1) \
+ return REG_BADPAT; \
+ dest = malloc(destsz + 1); \
+ if (dest == NULL) \
+ return REG_ESPACE; \
+ wcstombs(dest, src, destsz); \
+ dest[destsz] = '\0'; \
+ } \
+
#define IS_OUT_OF_BOUNDS \
((!fg->reversed \
? ((type == STR_WIDE) ? ((j + fg->wlen) > len) \
@@ -630,7 +642,7 @@
if (escaped)
{
if (!_escmap)
- _escmap = malloc(n * sizeof(bool));
+ _escmap = calloc(n, sizeof(bool));
if (!_escmap)
{
free(tmp);
@@ -710,36 +722,38 @@
* than in to the wide string so traverse the converted string, as well,
* to store these positions.
*/
- if (fg->hasdot || (fg->wescmap != NULL))
- {
- if (fg->wescmap != NULL)
- {
- fg->escmap = malloc(fg->len * sizeof(bool));
- if (!fg->escmap)
- {
- tre_free_fast(fg);
- return REG_ESPACE;
- }
+ if (fg->hasdot || (fg->wescmap != NULL)) {
+ if (fg->wescmap != NULL) {
+ fg->escmap = calloc(fg->len, sizeof(bool));
+ if (!fg->escmap) {
+ tre_free_fast(fg);
+ return REG_ESPACE;
+ }
}
- escaped = false;
- for (unsigned int i = 0; i < fg->len; i++)
- if (fg->pattern[i] == '\\')
- escaped = !escaped;
- else if (fg->pattern[i] == '.' && fg->escmap && escaped)
- {
- fg->escmap[i] = true;
- escaped = false;
- }
- else if (fg->pattern[i] == '.' && !escaped)
- {
- hasdot = i;
- if (firstdot == -1)
- firstdot = i;
- }
- else
- escaped = false;
- }
+ escaped = false;
+ char *_checkpat = NULL;
+ size_t _checklen = 0;
+ unsigned int escofs = 0;
+ /* Make a copy of the original pattern, because fg->pattern has already been stripped */
+ CONV_MBS_PAT(pat, _checkpat, _checklen);
+ for (unsigned int i = 0; i < n; i++) {
+ if (_checkpat[i] == '\\') {
+ escaped = !escaped;
+ if(escaped)
+ ++ escofs;
+ } else if (_checkpat[i] == '.' && fg->escmap && escaped) {
+ fg->escmap[i - escofs] = true;
+ escaped = false;
+ } else if (_checkpat[i] == '.' && !escaped) {
+ hasdot = i;
+ if (firstdot == -1)
+ firstdot = i;
+ } else
+ escaped = false;
+ }
+ free(_checkpat);
+ }
#else
SAVE_PATTERN(tmp, pos, fg->pattern, fg->len);
fg->escmap = _escmap;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 10, 6:29 PM (21 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31238750
Default Alt Text
D10098.id27039.diff (2 KB)
Attached To
Mode
D10098: bsdgrep(1): Fix escape map building for multibyte strings
Attached
Detach File
Event Timeline
Log In to Comment