]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Merged revisions 238630 via svnmerge from
authorMatthew Nicholson <mnicholson@digium.com>
Fri, 8 Jan 2010 19:33:53 +0000 (19:33 +0000)
committerMatthew Nicholson <mnicholson@digium.com>
Fri, 8 Jan 2010 19:33:53 +0000 (19:33 +0000)
https://origsvn.digium.com/svn/asterisk/trunk

................
  r238630 | mnicholson | 2010-01-08 13:32:11 -0600 (Fri, 08 Jan 2010) | 12 lines

  Merged revisions 238629 via svnmerge from
  https://origsvn.digium.com/svn/asterisk/branches/1.4

  ........
    r238629 | mnicholson | 2010-01-08 13:20:44 -0600 (Fri, 08 Jan 2010) | 5 lines

    Properly calculate the remaining space in the output string when reducing format strings.

    (closes issue #16560)
    Reported by: goldwein
  ........
................

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

main/file.c

index 8c4eb87debb4ab4d607928db8d835bfe73a1d1b2..cd7063ab47dfd9bdec9839cbef0d15bbd377a6bc 100644 (file)
@@ -1360,6 +1360,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_RWLIST_RDLOCK(&formats)) {
                ast_log(LOG_WARNING, "Unable to lock format list\n");
@@ -1395,8 +1396,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;
                }
@@ -1411,8 +1413,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;
                }
        }