[asterisk-dev] [Code Review] 4554: clang compiler warning: -Wunused-value

Diederik de Groot reviewboard at asterisk.org
Fri Apr 3 20:56:20 CDT 2015



> On April 4, 2015, 12:40 a.m., rmudgett wrote:
> > /branches/13/channels/chan_iax2.c, lines 2009-2013
> > <https://reviewboard.asterisk.org/r/4554/diff/2/?file=73276#file73276line2009>
> >
> >     This change causes bugs.  It is supposed to return peer because it increased the ref.
> 
> Diederik de Groot wrote:
>     Stupid me. If should actually also check if ao2_ref did not return an error (-1).
> 
> rmudgett wrote:
>     The return value of ao2_ref is rarely used.  When it is it is to get the number of refs the object had before the call.  The -1 error return value is practically useless.  That value means a programming error because the object is invalid and you get bad magic number messages logged, assertion failures, and very likely crashes.

Ok, point taken. So that would mean that ao2_ref will be the biggest cause of "-Wunused-value" warning, even if we changed everything else, because it's return is rarely used :-)

I still think it is valid to NULL a pointer that might/might not vanish in the future (as with ao2_ref(xx, -1)). Same goes for example for ast_free, which does not null the pointer afterwards (or did i overlook something ?. It makes NULL pointer checks after such a free or unref a little bit pointless.

I know everything is working and asterisk-11 and asterisk-13 are pretty stable as far as i can tell, so not looking for extra work for any of us, just want to finish this point and move on.


- Diederik


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


On April 4, 2015, 1:15 a.m., Diederik de Groot wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/4554/
> -----------------------------------------------------------
> 
> (Updated April 4, 2015, 1:15 a.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Bugs: ASTERISK-24917
>     https://issues.asterisk.org/jira/browse/ASTERISK-24917
> 
> 
> Repository: Asterisk
> 
> 
> Description
> -------
> 
> clang's static analyzer will throw quite a number warnings / errors during compilation, some of which can be very helpfull in finding corner-case bugs. 
> 
> clang compiler warning:-Wunused-value
> 
> Changes:
> apps/app_agent_pool.c
> multiple occasions where return value from ast_channel_ref and ast_channel_unref is not checked not used.
> return value from AST_LIST_REMOVE should be checked.
> Possible issues with leaked logged reference (added remark)
> 
> channels/chan_iax2.c
> return values from ast_callid_ref and ast_callid_unref can/should be used to update the pointer
> return value from AST_SCHED_DEL should be used to update the scheduled variable
> return value from AST_LIST_REMOVE should be checked.
> 
> channels/iax2/parser.c
> return value from AST_LIST_REMOVE should be checked.
> 
> include/asterisk/stringfields.h
> Quick fix to send the returned value from ast_string_field_ptr_set into the void.
> 
> Work in Progress:
> There are too many sources issues with "-Wunused-value" for one person to create all the fixes. If we want to actually use this warning we will need a couple of extra hands-on.
> 
> Should we suppress "-Wunused-value" ? :
> I think some of the issues pointed out by clang could be very helpfull, for example the "unref/ref/AST_LIST_REMOVE" changes that where needed in chan_iax2.c and apps/app_agent_pool.c. Some others a less interesting, for example the SCHED_DEL fixes.
> 
> 
> Diffs
> -----
> 
>   /branches/13/include/asterisk/stringfields.h 433444 
>   /branches/13/channels/iax2/parser.c 433444 
>   /branches/13/channels/chan_iax2.c 433444 
>   /branches/13/apps/app_agent_pool.c 433444 
> 
> Diff: https://reviewboard.asterisk.org/r/4554/diff/
> 
> 
> Testing
> -------
> 
> Just to make it clear, this was just a sample / proposal to work through large set of -Wunused-value warnings return. Some of them could be interesting, others might not be be. 
> 
> Mostly looking for a discussion about which path to follow, and see if we can divvy up the work a little.
> 
> Compiles / Untested / Pretty certain it contains issue because of different way of dealing with return value from ..._unref.
> 
> 
> File Attachments
> ----------------
> 
> ASTCFLAGS="-Wno-error=unused-value" make &| grep "[-W" -B1 -A2
>   https://reviewboard.asterisk.org/media/uploaded/files/2015/03/28/83f2f382-9ef2-41cf-8e7a-c188c014c17e__make.report
> 
> 
> Thanks,
> 
> Diederik de Groot
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20150404/c63b7186/attachment-0001.html>


More information about the asterisk-dev mailing list