Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.257
diff -u -p -r1.257 pbx.c
--- pbx.c	8 Jul 2005 21:14:34 -0000	1.257
+++ pbx.c	10 Jul 2005 22:07:17 -0000
@@ -583,6 +583,19 @@ struct ast_app *pbx_findapp(const char *
 	return tmp;
 }
 
+/*
+ * copy the string at src into *dst, returns the original *dst and updates *dst
+ * to point after the copy.
+ * We assume that *dst has sufficient space for the string and terminator.
+ */
+static char *str_add(char **dst, const char *src)
+{
+	char *ret = *dst;
+	strcpy(ret, src);
+	*dst += strlen(ret) + 1;
+	return ret;
+}
+
 static struct ast_switch *pbx_findswitch(const char *sw)
 {
 	struct ast_switch *asw;
@@ -3954,11 +3967,8 @@ int ast_context_add_include2(struct ast_
 	/* ... fill in this structure ... */
 	memset(new_include, 0, length);
 	p = new_include->stuff;
-	new_include->name = p;
-	strcpy(new_include->name, value);
-	p += strlen(value) + 1;
-	new_include->rname = p;
-	strcpy(new_include->rname, value);
+	new_include->name = str_add(&p, value);
+	new_include->rname = str_add(&p, value);
 	c = new_include->rname;
 	/* Strip off timing info */
 	while(*c && (*c != '|')) 
@@ -4072,17 +4082,8 @@ int ast_context_add_switch2(struct ast_c
 	/* ... fill in this structure ... */
 	memset(new_sw, 0, length);
 	p = new_sw->stuff;
-	new_sw->name = p;
-	strcpy(new_sw->name, value);
-	p += strlen(value) + 1;
-	new_sw->data = p;
-	if (data) {
-		strcpy(new_sw->data, data);
-		p += strlen(data) + 1;
-	} else {
-		strcpy(new_sw->data, "");
-		p++;
-	}
+	new_sw->name = str_add(&p, value);
+	new_sw->data = str_add(&p, data ? data : "");
 	if (eval) 
 		new_sw->tmpdata = p;
 	new_sw->next      = NULL;
@@ -4374,27 +4375,19 @@ int ast_async_goto_by_name(const char *c
 	return res;
 }
 
-static int ext_strncpy(char *dst, const char *src, int len)
+/*
+ * copy src to dst skipping blanks, return len including the final '\0'
+ * src is guaranteed to fit in dst
+ */
+static int ext_strcpy(char *dst, const char *src)
 {
-	int count=0;
+	char *base = dst;
 
-	while(*src && (count < len - 1)) {
-		switch(*src) {
-		case ' ':
-			/*	otherwise exten => [a-b],1,... doesn't work */
-			/*		case '-': */
-			/* Ignore */
-			break;
-		default:
-			*dst = *src;
-			dst++;
-		}
-		src++;
-		count++;
-	}
-	*dst = '\0';
-
-	return count;
+	for (; *src; src++)
+		if (*src != ' ')
+			*dst++ = *src;
+	*dst++ = '\0';
+	return dst - base;
 }
 
 static void null_datad(void *foo)
@@ -4453,17 +4446,14 @@ int ast_add_extension2(struct ast_contex
 	if (tmp) {
 		memset(tmp, 0, length);
 		p = tmp->stuff;
-		if (label) {
-			tmp->label = p;
-			strcpy(tmp->label, label);
-			p += strlen(label) + 1;
-		}
+		if (label)
+			tmp->label = str_add(&p, label);
 		tmp->exten = p;
-		p += ext_strncpy(tmp->exten, extension, strlen(extension) + 1) + 1;
+		p += ext_strcpy(tmp->exten, extension);
 		tmp->priority = priority;
 		tmp->cidmatch = p;
 		if (callerid) {
-			p += ext_strncpy(tmp->cidmatch, callerid, strlen(callerid) + 1) + 1;
+			p += ext_strcpy(tmp->cidmatch, callerid);
 			tmp->matchcid = 1;
 		} else {
 			tmp->cidmatch[0] = '\0';
@@ -5222,20 +5212,14 @@ static int pbx_builtin_resetcdr(struct a
 static int pbx_builtin_setaccount(struct ast_channel *chan, void *data)
 {
 	/* Copy the account code  as specified */
-	if (data)
-		ast_cdr_setaccount(chan, (char *)data);
-	else
-		ast_cdr_setaccount(chan, "");
+	ast_cdr_setaccount(chan, data ? (char *)data : "");
 	return 0;
 }
 
 static int pbx_builtin_setamaflags(struct ast_channel *chan, void *data)
 {
 	/* Copy the AMA Flags as specified */
-	if (data)
-		ast_cdr_setamaflags(chan, (char *)data);
-	else
-		ast_cdr_setamaflags(chan, "");
+	ast_cdr_setamaflags(chan, data ? (char *)data : "");
 	return 0;
 }
 
@@ -5812,8 +5796,8 @@ static int pbx_builtin_saynumber(struct 
 {
 	int res = 0;
 	char tmp[256];
-	char *number = (char *) NULL;
-	char *options = (char *) NULL;
+	char *number;
+	char *options;
 
 	
 	if (!data || ast_strlen_zero((char *)data)) {
@@ -6060,10 +6044,10 @@ struct ast_ignorepat *ast_walk_context_i
 
 int ast_context_verify_includes(struct ast_context *con)
 {
-	struct ast_include *inc;
+	struct ast_include *inc = NULL;
 	int res = 0;
 
-	for (inc = ast_walk_context_includes(con, NULL); inc; inc = ast_walk_context_includes(con, inc))
+	while ( (inc = ast_walk_context_includes(con, inc)) != NULL)
 		if (!ast_context_find(inc->rname)) {
 			res = -1;
 			ast_log(LOG_WARNING, "Context '%s' tries includes nonexistent context '%s'\n",
@@ -6100,9 +6084,8 @@ int ast_async_goto_if_exists(struct ast_
 
 int ast_parseable_goto(struct ast_channel *chan, const char *goto_string) 
 {
-	char *s;
 	char *exten, *pri, *context;
-	char *stringp=NULL;
+	char *stringp;
 	int ipri;
 	int mode = 0;
 
@@ -6110,8 +6093,7 @@ int ast_parseable_goto(struct ast_channe
 		ast_log(LOG_WARNING, "Goto requires an argument (optional context|optional extension|priority)\n");
 		return -1;
 	}
-	s = ast_strdupa(goto_string);
-	stringp=s;
+	stringp = ast_strdupa(goto_string);
 	context = strsep(&stringp, "|");
 	exten = strsep(&stringp, "|");
 	if (!exten) {
