[Freeswitch-svn] [commit] r3561 - freeswitch/trunk/src

Freeswitch SVN anthm at freeswitch.org
Wed Dec 6 19:36:00 EST 2006


Author: anthm
Date: Wed Dec  6 19:36:00 2006
New Revision: 3561

Modified:
   freeswitch/trunk/src/switch_channel.c

Log:
come down from the acid trip from the last commit

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Wed Dec  6 19:36:00 2006
@@ -1107,6 +1107,16 @@
 
 }
 
+#define resize(l) {\
+char *dp;\
+olen += (len + l + block);\
+cpos = c - data;\
+if ((dp = realloc(data, olen))) {\
+    data = dp;\
+    c = data + cpos;\
+    memset(c, 0, olen - cpos);\
+ }}                           \
+
 SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel, char *in)
 {
 	char *p, *c;
@@ -1129,15 +1139,17 @@
 
 			if (*p == '$') {
 				vtype = 1;
+                if (*(p+1) != '{') {
+                    vtype = 2;
+                }
 			}
-			if (*(p+1) != '{') {
-				vtype = 2;
-			}
-			
+
 			if (vtype) {
 				char *s = p, *e, *vname, *vval = NULL;
 				size_t nlen;
+
 				s++;
+
 				if (vtype == 1 && *s == '{') {
 					br = 1;
 					s++;
@@ -1195,24 +1207,23 @@
 				}
 				if ((nlen = sub_val ? strlen(sub_val) : 0)) {
 					if (len + nlen >= olen) {
-						char *dp;
-						olen += (len + nlen + block);
-						cpos = c - data;
-						if ((dp = realloc(data, olen))) {
-							data = dp;
-							c = data + cpos;
-							memset(c, 0, olen - cpos);
-						}
+                        resize(nlen);
 					}
 
 					len += nlen;
 					strcat(c, sub_val);
 					c += nlen;
-
 				}
 				
 				switch_safe_free(func_val);
+                sub_val = NULL;
+                vname = NULL;
+                vtype = 0;
 			}
+            if (len + 1 >= olen) {
+                resize(1);
+            }
+
 			if (sp) {
 				*c++ = ' ';
 				sp = 0;



More information about the Freeswitch-svn mailing list