]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
main/say: Work around gcc 9 format-truncation false positive
authorWalter Doekes <walter+asterisk@wjd.nu>
Thu, 4 Jun 2020 14:23:37 +0000 (16:23 +0200)
committerWalter Doekes <walter+asterisk@wjd.nu>
Thu, 29 Oct 2020 13:28:04 +0000 (08:28 -0500)
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

main/say.c

index 71d04f1d855ad245a03885e60f5b0af6da34e9e7..fcab7fd0ee6fbf661e03c8fe839832f428893150 100644 (file)
@@ -557,10 +557,10 @@ static int ast_say_number_full_en(struct ast_channel *chan, int num, const char
                } 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 {
@@ -1224,7 +1224,7 @@ static int ast_say_number_full_fr(struct ast_channel *chan, int num, const char
                                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;
@@ -1459,7 +1459,7 @@ static int ast_say_number_full_hu(struct ast_channel *chan, int num, const char
                } 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 {
@@ -2471,8 +2471,8 @@ static int ast_say_number_full_zh(struct ast_channel *chan, int num, const char
                        } 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++;
@@ -2480,7 +2480,7 @@ static int ast_say_number_full_zh(struct ast_channel *chan, int num, const char
                                }
                                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);
@@ -2656,7 +2656,7 @@ static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char
                        } 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 {
@@ -2824,10 +2824,10 @@ static int ast_say_number_full_vi(struct ast_channel *chan, int num, const char
                } 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++;