mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
for (var = head; var; var = var->next)
|
||||
resultslen += strlen(var->name) + strlen(var->value) + 2;
|
||||
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;
|
||||
|
||||
results = alloca(resultslen);
|
||||
out = ast_str_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);
|
||||
|
||||
|
Reference in New Issue
Block a user