[svn-commits] rizzo: trunk r48551 - /trunk/funcs/func_realtime.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Dec 17 15:57:46 MST 2006


Author: rizzo
Date: Sun Dec 17 16:57:46 2006
New Revision: 48551

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48551
Log:
replace ast_build_string() with ast_str_*().

Unless i am very mistaken, function_realtime_read() was
broken in that it would always return an empty string
(because ast_build_string() advanced the pointer to the
end of the string, and there was no reference to the
initial value.

This commit should fix this problem.


Modified:
    trunk/funcs/func_realtime.c

Modified: trunk/funcs/func_realtime.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_realtime.c?view=diff&rev=48551&r1=48550&r2=48551
==============================================================================
--- trunk/funcs/func_realtime.c (original)
+++ trunk/funcs/func_realtime.c Sun Dec 17 16:57:46 2006
@@ -49,8 +49,9 @@
 {
 	struct ast_variable *var, *head;
         struct ast_module_user *u;
-	char *results;
-	size_t resultslen = 0;
+	struct ast_str *out;
+	size_t resultslen;
+	int n;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(family);
 		AST_APP_ARG(fieldmatch);
@@ -80,13 +81,17 @@
 		ast_module_user_remove(u);
 		return -1;
 	}
+	resultslen = 0;
+	n = 0;
+	for (var = head; var; n++, var = var->next)
+		resultslen += strlen(var->name) + strlen(var->value);
+	/* add space for delimiters and final '\0' */
+	resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1;
+
+	out = ast_str_alloca(resultslen);
 	for (var = head; var; var = var->next)
-		resultslen += strlen(var->name) + strlen(var->value) + 2;
-
-	results = alloca(resultslen);
-	for (var = head; var; var = var->next)
-		ast_build_string(&results, &resultslen, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
-	ast_copy_string(buf, results, len);
+		ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
+	ast_copy_string(buf, out->str, len);
 
 	ast_module_user_remove(u);
 



More information about the svn-commits mailing list