[asterisk-dev] [Code Review]: avoid cppcheck warnings

junky reviewboard at asterisk.org
Thu Jan 5 20:13:02 CST 2012



> On Jan. 5, 2012, 10:54 a.m., Mark Michelson wrote:
> > trunk/addons/chan_ooh323.c, line 3677
> > <https://reviewboard.asterisk.org/r/1651/diff/1/?file=22543#file22543line3677>
> >
> >     Since res will always be 0 here, I think it's more clear to keep this as "return 0;". Instead, I think you should remove the res variable from this function.

removed the res variable, since reload_config() always return 0.


> On Jan. 5, 2012, 10:54 a.m., Mark Michelson wrote:
> > trunk/apps/app_chanspy.c, lines 975-976
> > <https://reviewboard.asterisk.org/r/1651/diff/1/?file=22544#file22544line975>
> >
> >     Instead of getting rid of "num" change line 975 to use "num" as its second argument.
> >     
> >     Also, I'm not a fan of using atoi() in this way. atoi() will return 0 if the input cannot be parsed as a number OR if the number is 0. strtol() is better for this sort of thing.
> 
> Matt Jordan wrote:
>     strtol returns a 0 in the case of a conversion error as well.  You could check the errno after the conversion, but in general, sscanf is the preferred option.

just by using the num variable in the ast_say_digits(), it avoid the cppcheck warning.


> On Jan. 5, 2012, 10:54 a.m., Mark Michelson wrote:
> > trunk/apps/app_voicemail.c, lines 3060-3069
> > <https://reviewboard.asterisk.org/r/1651/diff/1/?file=22548#file22548line3060>
> >
> >     There is a bug here, but your change is not fixing it.
> >     
> >     The first line in the else block should be using "quote + 1" instead of "buf + 1" in the strchr() call. Make that change instead.
> 
> rmudgett wrote:
>     There are more problems with this code than what you have pointed out since strchr can return NULL and eol_pnt is used without checking for it.
>     Also shouldn't the return value be quote + 1 instead of buf + 1 ?
> 
> Mark Michelson wrote:
>     Indeed. It should probably be something like:
>     
>     if (!(quote = strchr(buf, '\"'))) {
>         if ((eol_pnt = strchr(buf, '/')) || (eol_pnt = strchr(buf, '}'))) {
>             *eol_pnt = '\0';
>         }
>         return buf;
>     } else {
>         if ((eol_pnt = strchr(quote + 1, '\"'))) {
>             *eol_pnt = '\0';
>         }
>         return quote + 1;
>     }
> 
> wdoekes wrote:
>     P.S.: '\"' should be just '"'

added what Mark proposed.


- junky


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1651/#review5107
-----------------------------------------------------------


On Jan. 5, 2012, 8:12 p.m., junky wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1651/
> -----------------------------------------------------------
> 
> (Updated Jan. 5, 2012, 8:12 p.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> By running cppcheck 1.52, i realized there was many errors/warnings.
> 
> This patch fixes many of those.
> 
> 
> Diffs
> -----
> 
>   trunk/addons/chan_mobile.c 349670 
>   trunk/addons/chan_ooh323.c 349670 
>   trunk/apps/app_chanspy.c 349670 
>   trunk/apps/app_minivm.c 349670 
>   trunk/apps/app_osplookup.c 349670 
>   trunk/apps/app_queue.c 349670 
>   trunk/apps/app_voicemail.c 349670 
>   trunk/funcs/func_env.c 349670 
>   trunk/funcs/func_odbc.c 349670 
>   trunk/funcs/func_strings.c 349670 
>   trunk/main/pbx.c 349670 
> 
> Diff: https://reviewboard.asterisk.org/r/1651/diff
> 
> 
> Testing
> -------
> 
> still compile fine.
> Shouldn't have any impact on the code execution.
> 
> 
> Thanks,
> 
> junky
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20120106/2222b456/attachment-0001.htm>


More information about the asterisk-dev mailing list