diff --git a/Build/smokeview/Makefile b/Build/smokeview/Makefile index 06c302d4a..d48413025 100644 --- a/Build/smokeview/Makefile +++ b/Build/smokeview/Makefile @@ -46,18 +46,18 @@ bin = . # Definition of the object variables -csrc = callbacks.c camera.c color2rgb.c readimage.c readgeom.c readobject.c readcad.c colortimebar.c compress.c csphere.c dmalloc.c \ - drawGeometry.c file_util.c getdata.c getdatabounds.c getdatacolors.c glew.c \ - histogram.c infoheader.c readlabel.c readtour.c readhvac.c readslice.c readsmoke.c colorbars.c colorbar_defs.c \ - IOboundary.c IOgeometry.c IOhvac.c IOiso.c IOobjects.c IOpart.c IOplot2d.c IOplot3d.c \ - IOscript.c IOshooter.c IOslice.c IOsmoke.c IOtour.c IOvolsmoke.c IOwui.c IOzone.c IOframe.c isobox.c \ - main.c md5.c menus.c output.c readsmv.c renderhtml.c renderimage.c scontour2d.c sha1.c \ - sha256.c shaders.c showscene.c skybox.c smokestream.c smokeview.c smv_geometry.c startup.c fopen.c \ - stdio_buffer.c stdio_m.c string_util.c threader.c translate.c unit.c update.c viewports.c colortable.c command_args.c - -cppsrc = glui_bounds.cpp \ - glui_clip.cpp glui_colorbar.cpp glui_display.cpp glui_geometry.cpp glui_motion.cpp glui_objects.cpp \ - glui_shooter.cpp glui_smoke.cpp glui_stereo.cpp glui_tour.cpp glui_trainer.cpp +csrc = callbacks.c camera.c color2rgb.c readimage.c readgeom.c readobject.c readcad.c colortimebar.c \ + clang_test.c compress.c csphere.c dmalloc.c drawGeometry.c file_util.c getdata.c getdatabounds.c \ + getdatacolors.c glew.c histogram.c infoheader.c readlabel.c readtour.c readhvac.c readslice.c \ + readsmoke.c colorbars.c colorbar_defs.c IOboundary.c IOgeometry.c IOhvac.c IOiso.c IOobjects.c \ + IOpart.c IOplot2d.c IOplot3d.c IOscript.c IOshooter.c IOslice.c IOsmoke.c IOtour.c IOvolsmoke.c \ + IOwui.c IOzone.c IOframe.c isobox.c main.c md5.c menus.c output.c readsmv.c renderhtml.c \ + renderimage.c scontour2d.c sha1.c sha256.c shaders.c showscene.c skybox.c smokestream.c \ + smokeview.c smv_geometry.c startup.c fopen.c stdio_buffer.c stdio_m.c string_util.c threader.c \ + translate.c unit.c update.c viewports.c colortable.c command_args.c + +cppsrc = glui_bounds.cpp glui_clip.cpp glui_colorbar.cpp glui_display.cpp glui_geometry.cpp glui_motion.cpp \ + glui_objects.cpp glui_shooter.cpp glui_smoke.cpp glui_stereo.cpp glui_tour.cpp glui_trainer.cpp src = $(csrc) $(cppsrc) @@ -67,13 +67,13 @@ obj = $(cobj) $(cppobj) # setup for analyzing smokeview source code using clang -cclang = $(csrc:.c=.chk) -cppclang = $(cppsrc:.cpp=.chk) -clangchk = $(cclang) $(cppclang) +linux_osx_c_chk = $(csrc:.c=.chk) +linux_osx_cpp_chk = $(cppsrc:.cpp=.chk) +linux_osx_chk = $(linux_osx_c_chk) $(linux_osx_cpp_chk) -wincclang = $(csrc:.c=.winchk) -wincppclang = $(cppsrc:.cpp=.winchk) -winclangchk = $(wincclang) $(wincppclang) +win_c_chk = $(csrc:.c=.winchk) +win_cpp_chk = $(cppsrc:.cpp=.winchk) +win_chk = $(win_c_chk) $(win_cpp_chk) #CLANGANALYZE=clang --analyze -Xanalyzer -analyzer-checker=core,deadcode CLANGANALYZE=clang --analyze @@ -394,15 +394,14 @@ gnu_linux_64_check : $(src) # ------------- linux_osx_check ---------------- linux_osx_check : CFLAGS = -linux_osx_check : $(clangchk) +linux_osx_check : $(linux_osx_chk) $(CLANGSUMMARY) smokeview.summary # ------------- win_check ---------------- -# (not working yet) win_check : CFLAGS = -D NDEBUG -D WIN32 -D _CONSOLE -D X64 -D GLEW_STATIC -D PTW32_STATIC_LIB win_check : INC += $(WININC) -win_check : $(winclangchk) +win_check : $(win_chk) $(CLANGWINSUMMARY) smokeview.summary # VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV diff --git a/Source/scripts/check_code.bat b/Source/scripts/check_code.bat index b5f0098e2..8fada2031 100644 --- a/Source/scripts/check_code.bat +++ b/Source/scripts/check_code.bat @@ -1,8 +1,13 @@ @echo off set file=%1 +set option=%2 for %%f in (%file%) do ( set base=%%~nf ) -set OPTS=-D NDEBUG -D WIN32 -D _CONSOLE -D X64 -D GLEW_STATIC -D PTW32_STATIC_LIB +set "CLANGOPTS=--analyze" +if not "x%option%" == "x-t%" goto endif1 + set "CLANGOPTS=--analyze -Xanalyzer -analyzer-checker=core,deadcode -D pp_CLANG_TEST" +:endif1 +set COPTS=-D NDEBUG -D WIN32 -D _CONSOLE -D X64 -D GLEW_STATIC -D PTW32_STATIC_LIB set INC=-I ../glut_gl -I ../pthreads -I ../smokeview -I ../glui_v2_1_beta -I ../shared -I ../glew -I . -I ../gd-2.0.15 -I ../zlib128 %file% -clang --analyze %INC% %OPTS% %file% 2> %base%.chk +clang %CLANGOPTS% %INC% %COPTS% %file% 2> %base%.chk diff --git a/Source/scripts/check_code.sh b/Source/scripts/check_code.sh index e64e316b2..ee9446c4e 100755 --- a/Source/scripts/check_code.sh +++ b/Source/scripts/check_code.sh @@ -1,13 +1,17 @@ #!/bin/bash file=$1 +option=$2 + if [ ! -e $file ]; then echo *error: $file does not exist exit fi base=${file%.*} chkfile=${base}.chk -#CHECKS="-Xanalyzer -analyzer-checker=core.DivideZero" CHECKS= +if [ "$option" == "-t" ]; then + CHECKS="-Xanalyzer -analyzer-checker=core,deadcode -D pp_CLANG_TEST" +fi INC="-I ../smokeview -I ../glui_v2_1_beta -I ../shared -I ../glew -I . -I ../gd-2.0.15 -I ../zlib128" clang --analyze $CHECKS $INC $file >& $chkfile nwarnings=`tail -1 $chkfile | awk '{print $1}'` diff --git a/Source/smokeview/clang_test.c b/Source/smokeview/clang_test.c new file mode 100644 index 000000000..6872c2925 --- /dev/null +++ b/Source/smokeview/clang_test.c @@ -0,0 +1,35 @@ +#include "options.h" +#ifdef pp_CLANG_TEST +#include +#include +#include +#include +#include + +/* ----------------------- test1 ----------------------------- */ + +void test1(void){ +int a=0, b, c=0, d, e; +int *array=NULL, *barray, carray[3]; + +// divide by zero +b=1/a; + +//use undefined value +c=c+d; + +//access NULL array +c=array[0]; + +//access undefined array +d=barray[0]; + +//access undefined array position +e=carray[0]; + +return; +// dead code +b=1; +c=1; +} +#endif diff --git a/Source/smokeview/options.h b/Source/smokeview/options.h index dd6f14efe..c4711cc01 100644 --- a/Source/smokeview/options.h +++ b/Source/smokeview/options.h @@ -16,6 +16,7 @@ //#define pp_TOUR_SNAP // turn on tour snap option //#define pp_BOUND_FACE // show hide obst face independently when visualizing boundary files //#define pp_DEPRECATED // hide code not needed any more +//#define pp_CLANG_TEST // turn on to test clang --analyze #ifdef pp_FRAME // turn on each frame type if pp_FRAME is set #define pp_BOUNDFRAME // turn on frame code for boundary files