diff options
author | mnicholson <mnicholson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-01-08 19:20:44 +0000 |
---|---|---|
committer | mnicholson <mnicholson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-01-08 19:20:44 +0000 |
commit | 9bfa8fb1e242c6f5550b8f5f3a1eb7e67cc04cbc (patch) | |
tree | adbc31e58427276df99a9a0debb5c4d7cdc39f54 /main | |
parent | b2ffcef3b9eba15cb7756958a84c7d83a8d1d2bc (diff) |
Properly calculate the remaining space in the output string when reducing format strings.
(closes issue #16560)
Reported by: goldwein
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@238629 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/file.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/main/file.c b/main/file.c index 8d254b143..6d5414c16 100644 --- a/main/file.c +++ b/main/file.c @@ -1367,6 +1367,7 @@ char *ast_format_str_reduce(char *fmts) char *orig = fmts; int i, j, x, first, found = 0; int len = strlen(fmts) + 1; + int res; if (AST_LIST_LOCK(&formats)) { ast_log(LOG_WARNING, "Unable to lock format list\n"); @@ -1402,8 +1403,9 @@ char *ast_format_str_reduce(char *fmts) /* special handling for the first entry */ if (first) { - fmts += snprintf(fmts, len, "%s", fmts_str[i]); - len -= (fmts - orig); + res = snprintf(fmts, len, "%s", fmts_str[i]); + fmts += res; + len -= res; first = 0; continue; } @@ -1418,8 +1420,9 @@ char *ast_format_str_reduce(char *fmts) } if (!found) { - fmts += snprintf(fmts, len, "|%s", fmts_str[i]); - len -= (fmts - orig); + res = snprintf(fmts, len, "|%s", fmts_str[i]); + fmts += res; + len -= res; } } |