[svn-commits] trunk - r7472 /trunk/apps/app_macro.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Dec 13 16:03:07 CST 2005


Author: russell
Date: Tue Dec 13 16:03:06 2005
New Revision: 7472

URL: http://svn.digium.com/view/asterisk?rev=7472&view=rev
Log:
reduce some duplicated code when doing a strdup (issue #5986)

Modified:
    trunk/apps/app_macro.c

Modified: trunk/apps/app_macro.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_macro.c?rev=7472&r1=7471&r2=7472&view=diff
==============================================================================
--- trunk/apps/app_macro.c (original)
+++ trunk/apps/app_macro.c Tue Dec 13 16:03:06 2005
@@ -86,6 +86,11 @@
 STANDARD_LOCAL_USER;
 
 LOCAL_USER_DECL;
+
+static char *safe_strdup(const char *s)
+{
+	return s ? strdup(s) : NULL;
+}
 
 static int macro_exec(struct ast_channel *chan, void *data)
 {
@@ -162,25 +167,17 @@
 	}
 	argc = 1;
 	/* Save old macro variables */
-	save_macro_exten = pbx_builtin_getvar_helper(chan, "MACRO_EXTEN");
-	if (save_macro_exten) 
-		save_macro_exten = strdup(save_macro_exten);
+	save_macro_exten = safe_strdup(pbx_builtin_getvar_helper(chan, "MACRO_EXTEN"));
 	pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", oldexten);
 
-	save_macro_context = pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT");
-	if (save_macro_context)
-		save_macro_context = strdup(save_macro_context);
+	save_macro_context = safe_strdup(pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT"));
 	pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", oldcontext);
 
-	save_macro_priority = pbx_builtin_getvar_helper(chan, "MACRO_PRIORITY");
-	if (save_macro_priority) 
-		save_macro_priority = strdup(save_macro_priority);
+	save_macro_priority = safe_strdup(pbx_builtin_getvar_helper(chan, "MACRO_PRIORITY"));
 	snprintf(pc, sizeof(pc), "%d", oldpriority);
 	pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", pc);
   
-	save_macro_offset = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET");
-	if (save_macro_offset) 
-		save_macro_offset = strdup(save_macro_offset);
+	save_macro_offset = safe_strdup(pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"));
 	pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", NULL);
 
 	/* Setup environment for new run */



More information about the svn-commits mailing list