Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Sep 2011 16:50:24 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r225336 - user/gabor/grep/trunk/regex
Message-ID:  <201109021650.p82GoOtJ007597@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gabor
Date: Fri Sep  2 16:50:24 2011
New Revision: 225336
URL: http://svn.freebsd.org/changeset/base/225336

Log:
  - Be more verbose with debug information
  - Fix a bug in dot handling
  - Do not cast to unsigned char because it can cause a segfault
  - Add an include to glue.h for consistency

Modified:
  user/gabor/grep/trunk/regex/glue.h
  user/gabor/grep/trunk/regex/tre-fastmatch.c

Modified: user/gabor/grep/trunk/regex/glue.h
==============================================================================
--- user/gabor/grep/trunk/regex/glue.h	Fri Sep  2 16:46:42 2011	(r225335)
+++ user/gabor/grep/trunk/regex/glue.h	Fri Sep  2 16:50:24 2011	(r225336)
@@ -7,6 +7,7 @@
 #undef RE_DUP_MAX
 #include <regex.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #define TRE_WCHAR			1
 #define TRE_MULTIBYTE			1

Modified: user/gabor/grep/trunk/regex/tre-fastmatch.c
==============================================================================
--- user/gabor/grep/trunk/regex/tre-fastmatch.c	Fri Sep  2 16:46:42 2011	(r225335)
+++ user/gabor/grep/trunk/regex/tre-fastmatch.c	Fri Sep  2 16:50:24 2011	(r225336)
@@ -206,14 +206,14 @@ static int	fastcmp(const void *, const v
     fg->qsBc[i] = fg->len - fg->hasdot;					\
   for (int i = fg->hasdot + 1; i < fg->len; i++)			\
     {									\
-      fg->qsBc[(unsigned)fg->pattern[i]] = fg->len - i;			\
+      fg->qsBc[fg->pattern[i]] = fg->len - i;				\
       DPRINT(("BC shift for char %c is %d\n", fg->pattern[i],		\
 	     fg->len - i));						\
       if (fg->icase)							\
         {								\
           char c = islower(fg->pattern[i]) ? toupper(fg->pattern[i])	\
             : tolower(fg->pattern[i]);					\
-          fg->qsBc[(unsigned)c] = fg->len - i;				\
+          fg->qsBc[c] = fg->len - i;					\
 	  DPRINT(("BC shift for char %c is %d\n", c, fg->len - i));	\
         }								\
     }
@@ -397,12 +397,16 @@ static int	fastcmp(const void *, const v
       fg->matchall = true;						\
       fg->pattern = "";							\
       fg->wpattern = TRE_CHAR("");					\
+      DPRINT(("Matching every input\n"));				\
       return REG_OK;							\
     }									\
 									\
   /* Cannot handle REG_ICASE with MB string */				\
   if (fg->icase && (TRE_MB_CUR_MAX > 1))				\
-    return REG_BADPAT;							\
+    {									\
+      DPRINT(("Cannot use fast matcher for MBS with REG_ICASE\n"));	\
+      return REG_BADPAT;						\
+    }
 
 /*
  * Returns: REG_OK on success, error code otherwise
@@ -424,8 +428,8 @@ tre_compile_literal(fastmatch_t *fg, con
   SAVE_PATTERN(pat, n, fg->pattern, fg->len);
 #endif
 
-  DPRINT(("tre_compile_literal: pattern: %s, icase: %c, word: %c, "
-	 "newline %c\n", fg->pattern, fg->icase ? 'y' : 'n',
+  DPRINT(("tre_compile_literal: pattern: %s, len %u, icase: %c, word: %c, "
+	 "newline %c\n", fg->pattern, fg->len, fg->icase ? 'y' : 'n',
 	 fg->word ? 'y' : 'n', fg->newline ? 'y' : 'n'));
 
   FILL_QSBC;
@@ -496,7 +500,7 @@ tre_compile_fast(fastmatch_t *fg, const 
 	switch (pat[i])
 	  {
 	    case TRE_CHAR('.'):
-	      fg->hasdot = true;
+	      fg->hasdot = i;
 	      STORE_CHAR;
 	      break;
 	    case TRE_CHAR('$'):
@@ -606,8 +610,8 @@ badpat:
 
   xfree(tmp);
 
-  DPRINT(("tre_compile_fast: pattern: %s, bol %c, eol %c, "
-	 "icase: %c, word: %c, newline %c\n", fg->pattern,
+  DPRINT(("tre_compile_fast: pattern: %s, len %u, bol %c, eol %c, "
+	 "icase: %c, word: %c, newline %c\n", fg->pattern, fg->len,
 	 fg->bol ? 'y' : 'n', fg->eol ? 'y' : 'n',
 	 fg->icase ? 'y' : 'n', fg->word ? 'y' : 'n',
 	 fg->newline ? 'y' : 'n'));



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201109021650.p82GoOtJ007597>