Skip to content

Commit

Permalink
Merge pull request firemodels#2171 from gforney/master
Browse files Browse the repository at this point in the history
minor formatting edits to smokeview makefile, add some tests form clang --analyze
  • Loading branch information
gforney authored Jan 20, 2025
2 parents 85060fa + 87ca88c commit 7b6ca7b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
41 changes: 20 additions & 21 deletions Build/smokeview/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions Source/scripts/check_code.bat
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion Source/scripts/check_code.sh
Original file line number Diff line number Diff line change
@@ -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}'`
Expand Down
35 changes: 35 additions & 0 deletions Source/smokeview/clang_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "options.h"
#ifdef pp_CLANG_TEST
#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

/* ----------------------- 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
1 change: 1 addition & 0 deletions Source/smokeview/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7b6ca7b

Please sign in to comment.