diff --git a/main/file.c b/main/file.c
index 075062ba3d91f14e1d0c91ad7bff88c0c487bb43..a5f85ffd577740b56634c2e0f1fd322541668bc4 100644
--- a/main/file.c
+++ b/main/file.c
@@ -1356,6 +1356,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");
@@ -1391,8 +1392,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;
 		}
@@ -1407,8 +1409,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;
 		}
 	}