[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase2 r307674 - /team/dvossel/fixtheworl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Feb 11 13:34:00 CST 2011


Author: dvossel
Date: Fri Feb 11 13:33:56 2011
New Revision: 307674

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=307674
Log:
Fixes core show translation to use a dynamically defined string.

The static string in defined on the stack was not large enough.

Modified:
    team/dvossel/fixtheworld_phase2/main/translate.c

Modified: team/dvossel/fixtheworld_phase2/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/translate.c?view=diff&rev=307674&r1=307673&r2=307674
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase2/main/translate.c Fri Feb 11 13:33:56 2011
@@ -847,6 +847,7 @@
 	int curlen = 0, longest = 0;
 	int f_len = 0;
 	const struct ast_format_list *f_list = ast_format_list_get((size_t *) &f_len);
+	struct ast_str *out = ast_str_create(1024);
 
 	AST_RWLIST_RDLOCK(&translators);
 	ast_cli(a->fd, "         Translation times between formats (in microseconds) for one second of data\n");
@@ -864,7 +865,6 @@
 	}
 
 	for (i = -1; i < f_len; i++) {
-		struct ast_str *out = ast_str_alloca(256);
 		x = -1;
 		if ((i >= 0) && ((x = format2index(f_list[i].format.id)) == -1)) {
 			continue;
@@ -877,7 +877,7 @@
 		if (i >= 0 && !strcmp(ast_getformatname(&f_list[i].format), "unknown")) {
 			continue;
 		}
-		ast_str_set(&out, -1, " ");
+		ast_str_set(&out, 0, " ");
 		for (k = -1; k < f_len; k++) {
 			y = -1;
 			if ((k >= 0) && ((y = format2index(f_list[k].format.id)) == -1)) {
@@ -900,24 +900,25 @@
 
 			if (x >= 0 && y >= 0 && matrix_get(x, y)->step) {
 				/* Actual codec output */
-				ast_str_append(&out, -1, "%*d", curlen + 1, (matrix_get(x, y)->table_cost/100));
+				ast_str_append(&out, 0, "%*d", curlen + 1, (matrix_get(x, y)->table_cost/100));
 			} else if (i == -1 && k >= 0) {
 				/* Top row - use a dynamic size */
-				ast_str_append(&out, -1, "%*s", curlen + 1, ast_getformatname(&f_list[k].format));
+				ast_str_append(&out, 0, "%*s", curlen + 1, ast_getformatname(&f_list[k].format));
 			} else if (k == -1 && i >= 0) {
 				/* Left column - use a static size. */
-				ast_str_append(&out, -1, "%*s", longest, ast_getformatname(&f_list[i].format));
+				ast_str_append(&out, 0, "%*s", longest, ast_getformatname(&f_list[i].format));
 			} else if (x >= 0 && y >= 0) {
 				/* Codec not supported */
-				ast_str_append(&out, -1, "%*s", curlen + 1, "-");
+				ast_str_append(&out, 0, "%*s", curlen + 1, "-");
 			} else {
 				/* Upper left hand corner */
-				ast_str_append(&out, -1, "%*s", longest, "");
-			}
-		}
-		ast_str_append(&out, -1, "\n");
+				ast_str_append(&out, 0, "%*s", longest, "");
+			}
+		}
+		ast_str_append(&out, 0, "\n");
 		ast_cli(a->fd, "%s", ast_str_buffer(out));
 	}
+	ast_free(out);
 	AST_RWLIST_UNLOCK(&translators);
 	ast_format_list_destroy(f_list);
 	return CLI_SUCCESS;
@@ -929,7 +930,7 @@
 	size_t len = 0;
 	int i;
 	const struct ast_format_list *format_list = ast_format_list_get(&len);
-	struct ast_str *str = ast_str_alloca(256);
+	struct ast_str *str = ast_str_alloca(1024);
 	struct ast_translator *step;
 	char tmp[256];
 




More information about the asterisk-commits mailing list