Skip to content
Snippets Groups Projects
Commit 7c5f06dd authored by Luigi Rizzo's avatar Luigi Rizzo
Browse files

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.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48551 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 18e50176
No related branches found
No related tags found
No related merge requests found
......@@ -49,8 +49,9 @@ static int function_realtime_read(struct ast_channel *chan, char *cmd, char *dat
{
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 @@ static int function_realtime_read(struct ast_channel *chan, char *cmd, char *dat
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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment