This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix re_compile_pattern


Hi!

info regex says:

`buffer'
`allocated'
     If you want `re_compile_pattern' to allocate memory for the
     compiled pattern, set both of these to zero.  If you have an
     existing block of memory (allocated with `malloc') you want Regex
     to use, set `buffer' to its address and `allocated' to its size (in
     bytes).

     `re_compile_pattern' uses `realloc' to extend the space for the
     compiled pattern as necessary.

>From this, I conclude applications are doing nothing wrong if they do:
struct re_compile_pattern re;
memset (&re, 0, sizeof(re));
re.buffer = malloc (4096);
re.allocated = 4096;
re_compile_pattern ("^\\(.*\\)$", 8, &re);

(there is no word about calloc anywhere), yet the new regex code depends
on it being zeroed (at least for those fields not initialized by init_dfa).
It worked just fine with the old regex.

2002-07-04  Jakub Jelinek  <jakub@redhat.com>

	* posix/regcomp.c (re_compile_internal): Move clearing of dfa...
	(init_dfa): ...here.

--- libc/posix/regcomp.c.jj	Wed Jun  5 10:27:39 2002
+++ libc/posix/regcomp.c	Thu Jul  4 14:07:57 2002
@@ -724,7 +724,6 @@ re_compile_internal (preg, pattern, leng
       dfa = re_realloc (preg->buffer, re_dfa_t, 1);
       if (dfa == NULL)
 	return REG_ESPACE;
-      memset (dfa, '\0', sizeof (re_dfa_t));
       preg->allocated = sizeof (re_dfa_t);
     }
   preg->buffer = (unsigned char *) dfa;
@@ -781,6 +780,9 @@ init_dfa (dfa, pat_len)
      int pat_len;
 {
   int table_size;
+
+  memset (dfa, '\0', sizeof (re_dfa_t));
+
   dfa->nodes_alloc = pat_len + 1;
   dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);
 


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]