[Asterisk-code-review] main/say: Work around gcc 9 format-truncation false positive (asterisk[13])

Walter Doekes asteriskteam at digium.com
Thu Jun 4 09:23:17 CDT 2020


Walter Doekes has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14501 )


Change subject: main/say: Work around gcc 9 format-truncation false positive
......................................................................

main/say: Work around gcc 9 format-truncation false positive

Version: gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Warning:
  say.c:2371:24: error: ā€˜%dā€™ directive output may be truncated writing
    between 1 and 11 bytes into a region of size 10
    [-Werror=format-truncation=]
  2371 |     snprintf(buf, 10, "%d", num);
  say.c:2371:23: note: directive argument in the range [-2147483648, 9]

That's not possible though, as the if() starts out checking for (num < 0),
making this Warning a false positive.

(Also replaced some else<TAB>if with else<SP>if while in the vicinity.)

Change-Id: Ic7a70120188c9aa525a6d70289385bfce878438a
---
M main/say.c
1 file changed, 10 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/14501/1

diff --git a/main/say.c b/main/say.c
index eae1769..e998f27 100644
--- a/main/say.c
+++ b/main/say.c
@@ -576,10 +576,10 @@
 		} else if (playh) {
 			ast_copy_string(fn, "digits/hundred", sizeof(fn));
 			playh = 0;
-		} else	if (num < 20) {
+		} else if (num < 20) {
 			snprintf(fn, sizeof(fn), "digits/%d", num);
 			num = 0;
-		} else	if (num < 100) {
+		} else if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
 			num %= 10;
 		} else {
@@ -1243,7 +1243,7 @@
 				return res;
 			ast_copy_string(fn, "digits/thousand", sizeof(fn));
 			num = num % 1000;
-		} else	if (num < 1000000000) {
+		} else if (num < 1000000000) {
 			res = ast_say_number_full_fr(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
 			if (res)
 				return res;
@@ -1478,7 +1478,7 @@
 		} else if (num < 30) {
 			ast_copy_string(fn, "digits/20on", sizeof(fn));
 			num -= 20;
-		} else	if (num < 100) {
+		} else if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
 			num %= 10;
 		} else {
@@ -2367,8 +2367,8 @@
 			} else if (playt) {
 				snprintf(fn, sizeof(fn), "digits/thousand");
 				playt = 0;
-			} else	if (num < 10) {
-				snprintf(buf, 10, "%d", num);
+			} else if (num < 10) {
+				snprintf(buf, 12, "%d", num);
 				if (last_length - strlen(buf) > 1 && last_length != 0) {
 					last_length = strlen(buf);
 					playz++;
@@ -2376,7 +2376,7 @@
 				}
 				snprintf(fn, sizeof(fn), "digits/%d", num);
 				num = 0;
-			} else	if (num < 100) {
+			} else if (num < 100) {
 				snprintf(buf, 10, "%d", num);
 				if (last_length - strlen(buf) > 1 && last_length != 0) {
 					last_length = strlen(buf);
@@ -2552,7 +2552,7 @@
 			} else {
 				num = 0;
 			}
-		} else	if (num < 20) {
+		} else if (num < 20) {
 			if (options && strlen(options) == 1 && num < 3) {
 			    snprintf(fn, sizeof(fn), "digits/%d%s", num, options);
 			} else {
@@ -2720,10 +2720,10 @@
 		} else if (playohz) {
 			ast_copy_string(fn, "digits/0-hundred-odd", sizeof(fn));
 			playohz = 0;
-		} else	if (num < 20) {
+		} else if (num < 20) {
 			snprintf(fn, sizeof(fn), "digits/%d", num);
 			num = 0;
-		} else	if (num < 100) {
+		} else if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
 			num %= 10;
 			if ((num == 5) || (num == 4) || (num == 1)) playl++;

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

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ic7a70120188c9aa525a6d70289385bfce878438a
Gerrit-Change-Number: 14501
Gerrit-PatchSet: 1
Gerrit-Owner: Walter Doekes <walter+asterisk at wjd.nu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200604/a2fad05e/attachment.html>


More information about the asterisk-code-review mailing list