[asterisk-commits] mmichelson: branch mmichelson/npm_fixes r181015 - /team/mmichelson/npm_fixes/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 10 18:14:05 CDT 2009


Author: mmichelson
Date: Tue Mar 10 18:14:01 2009
New Revision: 181015

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=181015
Log:
Remove some comments. Change allocation scheme for match_char struct.


Modified:
    team/mmichelson/npm_fixes/main/pbx.c

Modified: team/mmichelson/npm_fixes/main/pbx.c
URL: http://svn.digium.com/svn-view/asterisk/team/mmichelson/npm_fixes/main/pbx.c?view=diff&rev=181015&r1=181014&r2=181015
==============================================================================
--- team/mmichelson/npm_fixes/main/pbx.c (original)
+++ team/mmichelson/npm_fixes/main/pbx.c Tue Mar 10 18:14:01 2009
@@ -818,11 +818,11 @@
 {
 	int is_pattern; /* the pattern started with '_' */
 	int deleted;    /* if this is set, then... don't return it */
-	char *x;       /* the pattern itself-- matches a single char */
 	int specificity; /* simply the strlen of x, or 10 for X, 9 for Z, and 8 for N; and '.' and '!' will add 11 ? */
 	struct match_char *alt_char;
 	struct match_char *next_char;
 	struct ast_exten *exten; /* attached to last char of a pattern for exten */
+	char x[1];       /* the pattern itself-- matches a single char */
 };
 
 struct scoreboard  /* make sure all fields are 0 before calling new_find_extension */
@@ -1825,13 +1825,14 @@
 {
 	struct match_char *m;
 	
-	if (!(m = ast_calloc(1, sizeof(*m))))
+	if (!(m = ast_calloc(1, sizeof(*m) + strlen(pattern)))) {
 		return NULL;
-
-	if (!(m->x = ast_strdup(pattern))) {
-		ast_free(m);
-		return NULL;
-	}
+	}
+
+	/* strcpy is safe here since we know its size and have allocated
+	 * just enough space for when we allocated m
+	 */
+	strcpy(m->x, pattern);
 
 	/* the specificity scores are the same as used in the old
 	   pattern matcher. */
@@ -1956,11 +1957,6 @@
 		}
 		m2 = 0;
 		if (already && (m2=already_in_tree(m1,buf,pattern)) && m2->next_char) {
-			/* XXX MCM - I think it makes sense to check if m2->exten is non-NULL. If it is
-			 * then it means we've found a duplicate extension. In this particular scenario, what
-			 * we do is overwrite what was previously in m2 with what we are now parsing. At least
-			 * this weird logic is consistent (see further down).
-			 */
 			if (!(*(s1+1))) {  /* if this is the end of the pattern, but not the end of the tree, then mark this node with the exten...
 								a shorter pattern might win if the longer one doesn't match */
 				if (m2->exten) {
@@ -1972,22 +1968,10 @@
 			m1 = m2->next_char; /* m1 points to the node to compare against */
 			m0 = &m2->next_char; /* m0 points to the ptr that points to m1 */
 		} else { /* not already OR not m2 OR nor m2->next_char */
-			/* XXX MCM - if (m2) means that 'already' is true and that this exten already
-			 * exists in the trie. It also means that m2->next_char is NULL, meaning we have
-			 * found a duplicate extension. Logic appears to show that we point the new
-			 * match_char to the existing one. If we're at the end of the current exten, then
-			 * we will end up overwriting the exten currently in m2
-			 */
 			if (m2) {
 				if (findonly)
 					return m2;
 				m1 = m2; /* while m0 stays the same */
-			/* XXX MCM - This else means that m2 is NULL. This could mean that either 'already'
-			 * is false or that m2 did not already exist in the tree. In either case it means
-			 * that we are dealing with a pattern not previously existing in the tree and we
-			 * need to add a new node to the tree. Adding a new node does not necessarily indicate
-			 * that we are adding a new exten.
-			 */
 			} else {
 				if (findonly)
 					return m1;
@@ -2058,8 +2042,6 @@
 		pattern_tree->next_char = 0;
 	}
 	pattern_tree->exten = 0; /* never hurts to make sure there's no pointers laying around */
-	if (pattern_tree->x)
-		free(pattern_tree->x);
 	free(pattern_tree);
 }
 




More information about the asterisk-commits mailing list