[MPlayer-cvslog] r19090 - trunk/TOOLS/checktree.sh

ivo subversion at mplayerhq.hu
Sat Jul 15 00:05:50 CEST 2006


Author: ivo
Date: Sat Jul 15 00:05:49 2006
New Revision: 19090

Modified:
   trunk/TOOLS/checktree.sh

Log:
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



Modified: trunk/TOOLS/checktree.sh
==============================================================================
--- trunk/TOOLS/checktree.sh	(original)
+++ trunk/TOOLS/checktree.sh	Sat Jul 15 00:05:49 2006
@@ -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
+
+# -----------------------------------------------------------------------------



More information about the MPlayer-cvslog mailing list