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

Kevin Harwell asteriskteam at digium.com
Mon Jun 22 12:44:58 CDT 2020


Kevin Harwell has posted comments on this change. ( https://gerrit.asterisk.org/c/asterisk/+/14501 )

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


Patch Set 1: Code-Review-1

(1 comment)

https://gerrit.asterisk.org/c/asterisk/+/14501/1/main/say.c 
File main/say.c:

https://gerrit.asterisk.org/c/asterisk/+/14501/1/main/say.c@2371 
PS1, Line 2371: 				snprintf(buf, 12, "%d", num);
I find it odd it's not complaining about the other similar conversions. For instance another exact same snprintf is just a few lines below this one in another "if".

Also I wager it's fixed by bumping the 'n' value to 12 due to the compiler thinking that's the max size for an int conversion? Is that for 32-bit? Seemingly 64-bit would need to be bigger?

>From what I've read the compiler is complaining about this because the number copied might be truncated, which if so could cause an error. However, there is no check on the snprintf result to see if that's the case.

I think to fix this "buf" needs to be enlarged some (32?), and the 'n' value increased to sizeof(buf) - 1. That should ensure signed larger numbers are not truncated on different architectures for some implementation of "int" and hopefully avoids the warning.

Alternatively, or even better, but maybe not necessary here is also checking the return value and making sure there is no truncation error/problem.



-- 
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-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Comment-Date: Mon, 22 Jun 2020 17:44:58 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200622/3b16c40c/attachment.html>


More information about the asterisk-code-review mailing list