svn commit: r232222 - user/gabor/tre-integration/contrib/tre/lib

Gabor Kovesdan gabor at FreeBSD.org
Mon Feb 27 16:12:50 UTC 2012


Author: gabor
Date: Mon Feb 27 16:12:49 2012
New Revision: 232222
URL: http://svn.freebsd.org/changeset/base/232222

Log:
  - Avoid segfaults by adding and extra condition and initializing variables
    with NULL

Modified:
  user/gabor/tre-integration/contrib/tre/lib/mregcomp.c
  user/gabor/tre-integration/contrib/tre/lib/mregexec.c

Modified: user/gabor/tre-integration/contrib/tre/lib/mregcomp.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/mregcomp.c	Mon Feb 27 16:12:00 2012	(r232221)
+++ user/gabor/tre-integration/contrib/tre/lib/mregcomp.c	Mon Feb 27 16:12:49 2012	(r232222)
@@ -58,11 +58,12 @@ tre_mcompile(mregex_t *preg, size_t nr, 
 	     size_t *wn, const char **regex, size_t *n, int cflags)
 {
   int ret;
-  const wchar_t **frags;
-  size_t *siz;
-  wmsearch_t *wm;
+  const wchar_t **frags = NULL;
+  size_t *siz = NULL;
+  wmsearch_t *wm = NULL;
 
   preg->k = nr;
+  preg->searchdata = NULL;
   preg->patterns = xmalloc(nr * sizeof(regex_t));
   if (!preg->patterns)
     return REG_ESPACE;
@@ -152,7 +153,7 @@ err:
     xfree(wm);
 
 finish:
-  if (!(cflags & REG_LITERAL))
+  if (!(cflags & REG_LITERAL) && !(preg->type == MHEUR_SINGLE))
     {
       if (frags)
 	xfree(frags);
@@ -168,8 +169,8 @@ tre_mregncomp(mregex_t *preg, size_t nr,
 {
   int i, ret;
   const wchar_t **wr;
-  wchar_t **wregex;
-  size_t *wlen;
+  wchar_t **wregex = NULL;
+  size_t *wlen = NULL;
 
   wregex = xmalloc(nr * sizeof(wchar_t *));
   if (!wregex)
@@ -226,8 +227,8 @@ tre_mregwncomp(mregex_t *preg, size_t nr
 {
   int i, ret;
   const char **sr;
-  char **sregex;
-  size_t *slen;
+  char **sregex = NULL;
+  size_t *slen = NULL;
 
   sregex = xmalloc(nr * sizeof(char *));
   if (!sregex)

Modified: user/gabor/tre-integration/contrib/tre/lib/mregexec.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/mregexec.c	Mon Feb 27 16:12:00 2012	(r232221)
+++ user/gabor/tre-integration/contrib/tre/lib/mregexec.c	Mon Feb 27 16:12:49 2012	(r232222)
@@ -58,7 +58,7 @@ tre_mmatch(const void *str, size_t len, 
   int ret;
   bool need_offsets;
 
-  need_offsets = (((wmsearch_t *)(preg->searchdata))->cflags & REG_NOSUB) &&
+  need_offsets = (preg->searchdata && ((wmsearch_t *)(preg->searchdata))->cflags & REG_NOSUB) &&
 		 (nmatch > 0);
 
 #define INPUT(pos) ((type == STR_WIDE) ? (const void *)&str_wide[pos] : \


More information about the svn-src-user mailing list