# HG changeset patch # User ivo # Date 1152914749 0 # Node ID e5ec659ec1c653085cf111076335e4d8c9f461bd # Parent 675bcaf5280c5e93c57d8681faee2517d92b2cc1 added checks for stupid code like casting return value of malloc and friends, sizeof(char) and similar 1 byte types, &&1, ||0, +0, -0, *1, *0 typical usage: ./checktree.sh -none -stupid -showcont somefile.c diff -r 675bcaf5280c -r e5ec659ec1c6 TOOLS/checktree.sh --- a/TOOLS/checktree.sh Fri Jul 14 21:54:24 2006 +0000 +++ b/TOOLS/checktree.sh Fri Jul 14 22:05:49 2006 +0000 @@ -23,6 +23,7 @@ _rcsid=no _oll=no _charset=no +_stupid=no _showcont=no _color=yes @@ -48,6 +49,7 @@ _rcsid=yes _oll=yes _charset=yes + _stupid=yes } disable_all_tests() { @@ -58,6 +60,7 @@ _rcsid=no _oll=no _charset=no + _stupid=no } printoption() { @@ -112,6 +115,7 @@ printoption "rcsid " "test for missing RCS Id's" "$_rcsid" printoption "oll " "test for overly long lines" "$_oll" printoption "charset " "test for wrong charset" "$_charset" + printoption "stupid " "test for stupid code" "$_stupid" echo printoption "all " "enable all tests" "no" echo @@ -126,6 +130,12 @@ echo -e "If there are, -(no)svn has no effect.\n" exit ;; + -stupid) + _stupid=yes + ;; + -nostupid) + _stupid=no + ;; -charset) _charset=yes ;; @@ -300,3 +310,47 @@ fi # ----------------------------------------------------------------------------- + +if [ "$_stupid" == "yes" ]; then + printhead "checking for stupid code ..." + + # avoid false-positives in xpm files, docs, etc, only check .c and .h files + chfilelist=`echo $filelist | tr ' ' '\n' | grep "[\.][ch]$"` + + for i in calloc malloc realloc memalign av_malloc av_mallocz faad_malloc \ + lzo_malloc safe_malloc mpeg2_malloc _ogg_malloc; do + printhead "--> casting of void* $i()" + grep $_grepopts "([ ]*[a-zA-Z_]\+[ ]*\*.*)[ ]*$i" $chfilelist + done + + for i in "" signed unsigned; do + printhead "--> usage of sizeof($i char)" + grep $_grepopts "sizeof[ ]*([ ]*$i[ ]*char[ ]*)" $chfilelist + done + + for i in int8_t uint8_t; do + printhead "--> usage of sizeof($i)" + grep $_grepopts "sizeof[ ]*([ ]*$i[ ]*)" $chfilelist + done + + printhead "--> usage of &&1" + grep $_grepopts "&&[ ]*1" $chfilelist + + printhead "--> usage of ||0" + grep $_grepopts "||[ ]*0" $chfilelist + + # added a-fA-F_ to eliminate some false positives + printhead "--> usage of *0" + grep $_grepopts "[a-zA-Z0-9)]\+[ ]*\*[ ]*0[^.0-9xa-fA-F_]" $chfilelist + + printhead "--> usage of *1" + grep $_grepopts "[a-zA-Z0-9)]\+[ ]*\*[ ]*1[^.0-9ea-fA-F_]" $chfilelist + + printhead "--> usage of +0" + grep $_grepopts "[a-zA-Z0-9)]\+[ ]*+[ ]*0[^.0-9xa-fA-F_]" $chfilelist + + printhead "--> usage of -0" + grep $_grepopts "[a-zA-Z0-9)]\+[ ]*-[ ]*0[^.0-9xa-fA-F_]" $chfilelist +fi + +# -----------------------------------------------------------------------------