[Asterisk-code-review] say: Don't prepend ampersand erroneously. (asterisk[master])

N A asteriskteam at digium.com
Wed Sep 28 07:40:22 CDT 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19316 )


Change subject: say: Don't prepend ampersand erroneously.
......................................................................

say: Don't prepend ampersand erroneously.

Some logic in say.c for determining if we need
to also add an ampersand for file seperation was faulty,
as non-successful files would increment the count, causing
a leading ampersand to be added improperly.

This is fixed, and a unit test that captures this regression
is also added.

ASTERISK-30248 #close

Change-Id: I02c1d3a11d82fe4ea8b462070cbd1effb5834d2b
---
M funcs/func_sayfiles.c
M main/say.c
2 files changed, 34 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/16/19316/1

diff --git a/funcs/func_sayfiles.c b/funcs/func_sayfiles.c
index d3f3341..7e0ece2 100644
--- a/funcs/func_sayfiles.c
+++ b/funcs/func_sayfiles.c
@@ -211,6 +211,15 @@
 		res = AST_TEST_FAIL;
 	}
 
+	/* + should be ignored and there should not be a leading & */
+	ast_str_set(&expr, 0, "${SAYFILES(+18005551212,digits)}");
+	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
+	if (strcmp(ast_str_buffer(result), "digits/1&digits/8&digits/0&digits/0&digits/5&digits/5&digits/5&digits/1&digits/2&digits/1&digits/2") != 0) {
+		ast_test_status_update(test, "SAYFILES(+18005551212,digits) test failed ('%s')\n",
+				ast_str_buffer(result));
+		res = AST_TEST_FAIL;
+	}
+
 	ast_str_set(&expr, 0, "${SAYFILES(35,number)}");
 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
 	if (strcmp(ast_str_buffer(result), "digits/30&digits/5") != 0) {
diff --git a/main/say.c b/main/say.c
index b60d4bf..e9fc5c4 100644
--- a/main/say.c
+++ b/main/say.c
@@ -64,7 +64,7 @@
 	const char *fn;
 	char fnbuf[10], asciibuf[20] = "letters/ascii";
 	char ltr;
-	int num = 0;
+	int outnum = 0, num = 0;
 	int res = 0;
 	int upper = 0;
 	int lower = 0;
@@ -160,7 +160,7 @@
 		}
 		if ((fn && ast_fileexists(fn, NULL, lang) > 0) ||
 			(snprintf(asciibuf + 13, sizeof(asciibuf) - 13, "%d", str[num]) > 0 && ast_fileexists(asciibuf, NULL, lang) > 0 && (fn = asciibuf))) {
-			ast_str_append(&filenames, 0, (num == 0 ? "%s" : "&%s"), fn);
+			ast_str_append(&filenames, 0, (outnum++ == 0 ? "%s" : "&%s"), fn);
 		}
 		if (upper || lower) {
 			continue;
@@ -217,7 +217,7 @@
 	const char *fn;
 	char fnbuf[256];
 	char ltr;
-	int num = 0;
+	int outnum = 0, num = 0;
 
 	struct ast_str *filenames = ast_str_create(20);
 	if (!filenames) {
@@ -282,7 +282,7 @@
 			fn = fnbuf;
 		}
 		if (fn && ast_fileexists(fn, NULL, lang) > 0) {
-			ast_str_append(&filenames, 0, (num == 0 ? "%s" : "&%s"), fn);
+			ast_str_append(&filenames, 0, (outnum++ == 0 ? "%s" : "&%s"), fn);
 		}
 		num++;
 	}
@@ -300,7 +300,7 @@
 {
 	const char *fn;
 	char fnbuf[256];
-	int num = 0;
+	int outnum = 0, num = 0;
 
 	struct ast_str *filenames = ast_str_create(20);
 	if (!filenames) {
@@ -336,7 +336,7 @@
 			break;
 		}
 		if (fn && ast_fileexists(fn, NULL, lang) > 0) {
-			ast_str_append(&filenames, 0, (num == 0 ? "%s" : "&%s"), fn);
+			ast_str_append(&filenames, 0, (outnum++ == 0 ? "%s" : "&%s"), fn);
 		}
 		num++;
 	}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19316
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I02c1d3a11d82fe4ea8b462070cbd1effb5834d2b
Gerrit-Change-Number: 19316
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220928/c593621c/attachment.html>


More information about the asterisk-code-review mailing list