]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Properly calculate the remaining space in the output string when reducing format...
authorMatthew Nicholson <mnicholson@digium.com>
Fri, 8 Jan 2010 19:20:44 +0000 (19:20 +0000)
committerMatthew Nicholson <mnicholson@digium.com>
Fri, 8 Jan 2010 19:20:44 +0000 (19:20 +0000)
(closes issue #16560)
Reported by: goldwein

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@238629 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/file.c

index 8d254b143a9717045b64fe155dc4e87127b151aa..6d5414c16937ca83070b52638ef3950602d2f5bc 100644 (file)
@@ -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;
                }
        }