[FFmpeg-devel] [PATCH] Tell gcc not to "suggest" unnecessary parentheses

Eli Friedman eli.friedman
Tue Jul 6 21:18:18 CEST 2010


On Sat, Jul 3, 2010 at 12:59 PM, Rafa?l Carr? <rafael.carre at gmail.com> wrote:
> On Sat, 3 Jul 2010 12:20:17 -0700
> Eli Friedman <eli.friedman at gmail.com> wrote:
>
> Hi,
>
>> >> If I may give a suggestion, keep the warning as it can help
>> >> spotting
>> >>
>> >> if ( foo = 1 )
>> >>
>> >> where the assignment wasn't intended.
>> >
>> > does our patcheck check for this?
>>
>> Not at the moment... I'd write a patch, but my regex skills aren't
>> quite up to the task.
>
> I think "[^\(]\([^\(].*[^=]=[^=]" should do the trick:
>
> It should match one single opening parenthesis and one single = in the
> same line.
>
> Depending on code conventions it could have some false positives like:
> if ? ? ?(AAA ? ?&& ? ? ?\
> ? ? ? ?(x = y) && ? ? ?\
> ? ? ? ?BBB)

Limited patch attached... it's really difficult to catch everything
with regexes, but this should catch the most common cases (with some
false positives if people like writing "if (x) y=z;" on one line).

-Eli
-------------- next part --------------
Index: tools/patcheck
===================================================================
--- tools/patcheck	(revision 24068)
+++ tools/patcheck	(working copy)
@@ -43,6 +43,7 @@
 hiegrep '(static|inline|const) *\1'  'duplicate word' $*
 hiegrep 'INIT_VLC_USE_STATIC' 'forbidden ancient vlc type' $*
 hiegrep '=[-+\*\&] ' 'looks like compound assignment' $*
+hiegrep '(if|while) *\([^\(].*[^=]=[^=]' 'possible assignment inside conditional' $*
 
 hiegrep2 '(int|unsigned|static|void)[a-zA-Z0-9 _]*(init|end)[a-zA-Z0-9 _]*\(.*[^;]$' '(av_cold|:\+[^a-zA-Z_])' 'These functions may need av_cold, please review the whole patch for similar functions needing av_cold' $*
 



More information about the ffmpeg-devel mailing list