aboutsummaryrefslogtreecommitdiffstats
path: root/pbx.c
diff options
context:
space:
mode:
Diffstat (limited to 'pbx.c')
-rwxr-xr-xpbx.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/pbx.c b/pbx.c
index b4df9be52..767023c85 100755
--- a/pbx.c
+++ b/pbx.c
@@ -5667,24 +5667,25 @@ static int pbx_builtin_goto(struct ast_channel *chan, void *data)
int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size)
{
struct ast_var_t *variables;
- struct varshead *headp;
- char *var=NULL ,*val=NULL;
+ char *var, *val;
int total = 0;
- memset(buf,0,size);
- if (chan) {
- headp=&chan->varshead;
- AST_LIST_TRAVERSE(headp,variables,entries) {
- if(chan && variables && (var=ast_var_name(variables)) && (val=ast_var_value(variables)) && !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
- snprintf(buf + strlen(buf), size - strlen(buf), "%s=%s\n", var, val);
- if(strlen(buf) >= size) {
- ast_log(LOG_ERROR,"Data Buffer Size Exceeded!\n");
- break;
- }
- total++;
- } else
+ if (!chan)
+ return 0;
+
+ memset(buf, 0, size);
+
+ AST_LIST_TRAVERSE(&chan->varshead, variables, entries) {
+ if(variables &&
+ (var=ast_var_name(variables)) && (val=ast_var_value(variables)) &&
+ !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
+ if (ast_build_string(&buf, &size, "%s=%s\n", var, val)) {
+ ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
break;
- }
+ } else
+ total++;
+ } else
+ break;
}
return total;