Skip to content

Commit

Permalink
Merge pull request #1990 from JakeOShannessy/more-warnings
Browse files Browse the repository at this point in the history
cmake: enable more warnings for consistency across platforms
  • Loading branch information
gforney authored Aug 15, 2024
2 parents 65ec1e8 + 3ae4189 commit df2abd4
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 173 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Checks: "clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,readability-identifier-naming"
WarningsAsErrors: ""
HeaderFilterRegex: ""
AnalyzeTemporaryDtors: false
CheckOptions:
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
Expand Down
96 changes: 59 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,9 @@ if (LINUX)
add_definitions(-Dpp_LINUX)
endif()

if (NOT MSVC)
add_compile_options(-Wunused)
else()
add_compile_options(/W3)
endif()
# This is a set of warnings that are not enabled by default but it would be good
# to satisfy these.
if(STRICT_CHECKS)
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.*")
set(CMAKE_C_CLANG_TIDY "clang-tidy;-checks=clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.*")
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
add_compile_options(-O2)
add_compile_options(-flto=auto)
add_compile_options(-ffat-lto-objects)
add_compile_options(-fexceptions)
add_compile_options(-grecord-gcc-switches)
add_compile_options(-Wall)
add_compile_options(-Werror=format-security)
add_compile_options(-Wp,-D_FORTIFY_SOURCE=2)
add_compile_options(-Wp,-D_GLIBCXX_ASSERTIONS )
add_compile_options(-fstack-protector-strong)
add_compile_options(-fasynchronous-unwind-tables)
add_compile_options(-fstack-clash-protection -fcf-protection)
add_compile_options(-fcf-protection)
endif()
# GLUI has been modified for smokeview, so we have to vendor it and can't use a
# native version.
add_subdirectory(Source/glui_v2_1_beta)

find_package(OpenGL REQUIRED)
if (NOT(WIN32))
Expand All @@ -112,10 +90,6 @@ if (NOT ZLIB_FOUND)
add_subdirectory(Source/zlib128)
endif()

# GLUI has been modified for smokeview, so we have to vendor it and can't use a
# native version.
add_subdirectory(Source/glui_v2_1_beta)

# This fails on Windows so we disable it for now
if (NOT(WIN32))
find_package(PkgConfig)
Expand All @@ -135,6 +109,62 @@ if (WIN32)
endif()
endif()

if (LUA)
if (VENDOR_LFS)
add_subdirectory(Source/lfs)
endif()
if (VENDOR_LPEG)
add_subdirectory(Source/lpeg)
endif()
endif()


if (NOT MSVC)
add_compile_options(-Wunused)
else()
add_compile_options(/W3)
endif()
# This is a set of warnings that are not enabled by default but it would be good
# to satisfy these.
if(STRICT_CHECKS AND (NOT MSVC))
# set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.*")
# set(CMAKE_C_CLANG_TIDY "clang-tidy;-checks=clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.*")
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
add_compile_options(-O2)
add_compile_options(-fexceptions)
add_compile_options(-grecord-gcc-switches)
add_compile_options(-Wall)
add_compile_options(-Werror=format-security)
add_compile_options(-Wp,-D_FORTIFY_SOURCE=2)
add_compile_options(-Wp,-D_GLIBCXX_ASSERTIONS )
add_compile_options(-fstack-protector-strong)
add_compile_options(-fasynchronous-unwind-tables)
add_compile_options(-fstack-clash-protection)
add_compile_options(-fcf-protection)

add_compile_options(-Wno-unknown-pragmas)
add_compile_options(-Wno-uninitialized)
add_compile_options(-Wno-unused-result)
add_compile_options(-Wno-format-overflow)
add_compile_options(-Wno-format-truncation)
add_compile_options(-Wno-nonnull)
add_compile_options(-Wno-comment)
if (NOT (CMAKE_C_COMPILER_ID STREQUAL IntelLLVM))
add_compile_options(-Wno-stringop-truncation)
add_compile_options(-ffat-lto-objects)
add_compile_options(-flto=auto)
else()
# IntelLLVM-specific options
add_compile_options(-Wno-tautological-constant-compare)
add_compile_options(-Wno-for-loop-analysis)
endif()

add_compile_options(-Wshadow)
elseif(STRICT_CHECKS AND (NOT MSVC))
add_compile_options(/Wall)
add_compile_options(/Werror)
endif()

add_executable(smokeview
Source/smokeview/main.c
Source/smokeview/menus.c
Expand Down Expand Up @@ -281,8 +311,6 @@ else()
endif()
target_link_libraries(smokeview PRIVATE OpenGL::GL OpenGL::GLU)



target_include_directories(smokeview PRIVATE
Source/smokeview
Source/shared
Expand Down Expand Up @@ -353,12 +381,6 @@ if (LUA)
Source/smvluacore/camera.lua
DESTINATION ${CMAKE_INSTALL_DATADIR}/smokeview/scripts
)
if (VENDOR_LFS)
add_subdirectory(Source/lfs)
endif()
if (VENDOR_LPEG)
add_subdirectory(Source/lpeg)
endif()
endif()

if (MSVC)
Expand Down
16 changes: 8 additions & 8 deletions Source/background/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,20 +579,20 @@ int get_ncores(void){

/* ------------------ get_host_ncores ------------------------ */

int get_host_ncores(char *host){
int get_host_ncores(char *hosta){
FILE *stream;
char buffer[1024];
char command[1024];
char localfile[1024];
int ncores=0;

strcpy(localfile,"/tmp/cpuinfo.");
strcat(localfile,host);
strcat(localfile,hosta);
strcat(localfile,".");
strcat(localfile,pid);

strcpy(command,"ssh ");
strcat(command,host);
strcat(command,hosta);
strcat(command," cat /proc/cpuinfo >");
strcat(command,localfile);

Expand Down Expand Up @@ -620,20 +620,20 @@ int get_host_ncores(char *host){

/* ------------------ get_host_load ------------------------ */

float get_host_load(char *host){
float get_host_load(char *host_arg){
FILE *stream;
char buffer[1024];
char command[1024];
char localfile[1024];
float load1;

strcpy(localfile,"/tmp/loadavg.");
strcat(localfile,host);
strcat(localfile,host_arg);
strcat(localfile,".");
strcat(localfile,pid);

strcpy(command,"ssh ");
strcat(command,host);
strcat(command,host_arg);
strcat(command," cat /proc/loadavg >");
strcat(command,localfile);

Expand Down Expand Up @@ -674,11 +674,11 @@ float get_load(void){

/* ------------------ cpuusage_host ------------------------ */

unsigned char cpuusage_host(char *host, int ncores){
unsigned char cpuusage_host(char *hostb, int ncores){
float load;
unsigned char usage;

load = get_host_load(host);
load = get_host_load(hostb);
if(load>ncores)load=ncores;
usage = 100*(load/(float)ncores);
return usage;
Expand Down
17 changes: 8 additions & 9 deletions Source/env2mod/env2mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ int CreateModule(char *left_file, char* right_file, char *module_file){
}
}
else{
char *prepend_string, *append_string;
char *prepend_string, *append_string_local;

prepend_string = val_right;
append_string = match+strlen(val_left);
append_string_local = match+strlen(val_left);
match[0] = 0;

prepend_string = TrimFrontBack(prepend_string);
OutputPath(stream_module, ENV2MOD_PREPEND, key_right, prepend_string);

append_string = TrimFrontBack(append_string);
OutputPath(stream_module, ENV2MOD_APPEND, key_right, append_string);
append_string_local = TrimFrontBack(append_string_local);
OutputPath(stream_module, ENV2MOD_APPEND, key_right, append_string_local);
}
}
read_left = NextLine(buffer_left, LEN_BUFFER, stream_left);
Expand Down Expand Up @@ -323,17 +323,17 @@ int CreateScript(char *left_file, char* right_file, char *module_file){
}
}
else{
char *prepend_string, *append_string;
char *prepend_string, *append_string_local;

prepend_string = val_right;
append_string = match+strlen(val_left);
append_string_local = match+strlen(val_left);
match[0] = 0;

prepend_string = TrimFrontBack(prepend_string);
OutputScriptPath(stream_module, ENV2MOD_PREPEND, key_right, prepend_string);

append_string = TrimFrontBack(append_string);
OutputScriptPath(stream_module, ENV2MOD_APPEND, key_right, append_string);
append_string_local = TrimFrontBack(append_string_local);
OutputScriptPath(stream_module, ENV2MOD_APPEND, key_right, append_string_local);
}
}
read_left = NextLine(buffer_left, LEN_BUFFER, stream_left);
Expand Down Expand Up @@ -362,4 +362,3 @@ int CreateScript(char *left_file, char* right_file, char *module_file){
fclose(stream_module);
return 0;
}

4 changes: 2 additions & 2 deletions Source/flush/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ void Usage(char *prog, int option){

/* ------------------ FlushCache ------------------------ */
#define BUFFERSIZE 250000000
void FlushCache(float flush_size){
void FlushCache(float flush_size_arg){
int i, nbuffers;

nbuffers = (int)(flush_size+0.5);
nbuffers = (int)(flush_size_arg+0.5);
for(i = 0;i<nbuffers;i++){
int *buffptr;
int j;
Expand Down
6 changes: 3 additions & 3 deletions Source/smokediff/IOdboundary.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void DiffBoundarYes(FILE *stream_out){
for(;;){
int iq;
float f1, f2, dt;
int file_size;
int file_size_local;

if(error1!=0||error2!=0)break;

Expand All @@ -250,7 +250,7 @@ void DiffBoundarYes(FILE *stream_out){
}
patchtime2a=patchtime2b;
getpatchdata(unit2, boundary2->npatches,
p2i1, p2i2, p2j1, p2j2, p2k1, p2k2, &patchtime2b, pqq2b, &npqq2b, &file_size, &error2);
p2i1, p2i2, p2j1, p2j2, p2k1, p2k2, &patchtime2b, pqq2b, &npqq2b, &file_size_local, &error2);
if(error2!=0)break;
}
if(error2!=0)break;
Expand Down Expand Up @@ -294,7 +294,7 @@ void DiffBoundarYes(FILE *stream_out){
}

getpatchdata(unit1, boundary1->npatches,
p1i1, p1i2, p1j1, p1j2, p1k1, p1k2, &patchtime1, pqq1, &npqq1, &file_size, &error1);
p1i1, p1i2, p1j1, p1j2, p1k1, p1k2, &patchtime1, pqq1, &npqq1, &file_size_local, &error1);
}
PRINTF("\n");
FFLUSH();
Expand Down
48 changes: 25 additions & 23 deletions Source/smokeview/c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,27 +171,27 @@ int Loadsmvall(const char *input_filename) {
/// @param[out] fdsprefix
/// @param[out] input_filename_ext
/// @return
int ParseSmvFilepath(const char *smv_filepath, char *fdsprefix,
char *input_filename_ext) {
int ParseSmvFilepath(const char *smv_filepath, char *fdsprefix_arg,
char *input_filename_ext_arg) {
int len_casename;
strcpy(input_filename_ext, "");
strcpy(input_filename_ext_arg, "");
len_casename = (int)strlen(smv_filepath);
if(len_casename > 4) {
char *c_ext;

c_ext = strrchr(smv_filepath, '.');
if(c_ext != NULL) {
STRCPY(input_filename_ext, c_ext);
ToLower(input_filename_ext);
STRCPY(input_filename_ext_arg, c_ext);
ToLower(input_filename_ext_arg);

if(c_ext != NULL && (strcmp(input_filename_ext, ".smv") == 0 ||
strcmp(input_filename_ext, ".svd") == 0 ||
strcmp(input_filename_ext, ".smt") == 0)) {
if(c_ext != NULL && (strcmp(input_filename_ext_arg, ".smv") == 0 ||
strcmp(input_filename_ext_arg, ".svd") == 0 ||
strcmp(input_filename_ext_arg, ".smt") == 0)) {
// c_ext[0]=0;
STRCPY(fdsprefix, smv_filepath);
fdsprefix[strlen(fdsprefix) - 4] = 0;
strcpy(movie_name, fdsprefix);
strcpy(render_file_base, fdsprefix);
STRCPY(fdsprefix_arg, smv_filepath);
fdsprefix_arg[strlen(fdsprefix_arg) - 4] = 0;
strcpy(movie_name, fdsprefix_arg);
strcpy(render_file_base, fdsprefix_arg);
FREEMEMORY(trainer_filename);
NewMemory((void **)&trainer_filename, (unsigned int)(len_casename + 7));
STRCPY(trainer_filename, smv_filepath);
Expand All @@ -206,7 +206,7 @@ int ParseSmvFilepath(const char *smv_filepath, char *fdsprefix,
return 0;
}

int Loadsmv(char *input_filename, char *input_filename_ext) {
int Loadsmv(char *input_filename, char *input_filename_ext_arg) {
int return_code;
char *input_file;

Expand All @@ -221,13 +221,13 @@ int Loadsmv(char *input_filename, char *input_filename_ext) {
// setup input files names

input_file = smv_filename;
if(strcmp(input_filename_ext, ".svd") == 0 || demo_option == 1) {
if(strcmp(input_filename_ext_arg, ".svd") == 0 || demo_option == 1) {
trainer_mode = 1;
trainer_active = 1;
if(strcmp(input_filename_ext, ".svd") == 0) {
if(strcmp(input_filename_ext_arg, ".svd") == 0) {
input_file = trainer_filename;
}
else if(strcmp(input_filename_ext, ".smt") == 0) {
else if(strcmp(input_filename_ext_arg, ".smt") == 0) {
input_file = test_filename;
}
}
Expand Down Expand Up @@ -1254,7 +1254,7 @@ void Loadvolsmokeframe(int meshnumber, int framenumber, int flag) {
index = meshnumber;
framenum = framenumber;
if(index > nmeshes - 1) index = -1;
for(size_t i = 0; i < nmeshes; i++) {
for(i = 0; i < nmeshes; i++) {
if(index == i || index < 0) {
meshdata *meshi;
volrenderdata *vr;
Expand Down Expand Up @@ -1366,10 +1366,10 @@ void SetMovietype(const char *type) {

int GetMovietype() { return movie_filetype; }

void Makemovie(const char *name, const char *base, float framerate) {
void Makemovie(const char *name, const char *base, float framerate_arg) {
strcpy(movie_name, name);
strcpy(render_file_base, base);
movie_framerate = framerate;
movie_framerate = framerate_arg;
RenderCB(MAKE_MOVIE);
}

Expand Down Expand Up @@ -2720,10 +2720,12 @@ int SetP3dsurfacesmooth(int v) {

int SetScaledfont(int height2d, float height2dwidth, int thickness2d,
int height3d, float height3dwidth, int thickness3d) {
scaled_font2d_height = scaled_font2d_height;
scaled_font2d_height2width = scaled_font2d_height2width;
scaled_font3d_height = scaled_font3d_height;
scaled_font3d_height2width = scaled_font3d_height2width;
scaled_font2d_height = height2d;
scaled_font2d_height2width = height2dwidth;
scaled_font3d_height = height3d;
scaled_font3d_height2width = height3dwidth;
scaled_font2d_thickness = thickness2d;
scaled_font3d_thickness = thickness3d;
return 0;
} // SCALEDFONT

Expand Down
Loading

0 comments on commit df2abd4

Please sign in to comment.