From 21c01a5454c183a1c54105b1d239a57af4be69ed Mon Sep 17 00:00:00 2001 From: Scott Fennell Date: Tue, 6 Nov 2018 11:23:12 -0600 Subject: [PATCH] scan-build changes This reverts commit e86027f825a4ae8d885911dbb5ff13f3754ffab7. --- .../Interface_Code_Gen/CommentSaver.cpp | 14 +-- .../Interface_Code_Gen/FieldDescription.cpp | 35 ++++--- .../codegen/Interface_Code_Gen/Utilities.cpp | 7 +- .../data_products/EQParse/eqparse_evaluate.c | 4 +- .../data_products/EQParse/eqparse_funcsub.c | 4 +- .../data_products/EQParse/eqparse_takeinput.c | 1 - trick_source/data_products/Log/Csv.cpp | 2 +- trick_source/data_products/Log/Delta.cpp | 4 +- trick_source/data_products/Log/MatLab.cpp | 54 ++++++----- trick_source/data_products/Log/MatLab4.cpp | 12 ++- .../data_products/Log/TrickBinary.cpp | 6 +- trick_source/data_products/Log/log.cpp | 19 ++-- .../data_products/Log/parseLogHeader.cpp | 91 +++++++++++-------- trick_source/data_products/Var/var.cpp | 18 +++- trick_source/data_products/makefile | 2 + ...k2_midpoint_second_order_ode_integrator.cc | 1 + .../ClassicCheckPointerAgent.cpp | 7 +- .../CheckPointAgent/PythonPrint.cpp | 1 + .../DataRecord/DataRecordGroup.cpp | 2 +- .../sim_services/InputProcessor/IPPython.cpp | 2 +- .../JITInputFile/JITInputFile.cpp | 5 +- .../JSONVariableServerThread.cpp | 1 - trick_source/sim_services/MonteCarlo/Makefile | 2 + .../sim_services/MonteCarlo/MonteVarFile.cpp | 9 +- .../sim_services/MonteCarlo/test/Makefile | 2 +- .../VariableServerListenThread.cpp | 17 ++-- .../VariableServerThread_copy_sim_data.cpp | 5 +- .../VariableServerThread_loop.cpp | 4 +- .../comm/src/tc_init_mcast_client.c | 2 +- .../comm/src/tc_init_mcast_server.c | 2 +- .../trick_utils/comm/src/tc_init_udp_client.c | 2 +- .../trick_utils/comm/src/tc_init_udp_server.c | 2 +- .../trick_utils/shm/src/tsm_disconnect.c | 2 - .../trick_utils/trick_adt/src/MapStrToPtr.c | 5 +- trick_source/trick_utils/trick_adt/src/bst.c | 28 ++++-- 35 files changed, 226 insertions(+), 148 deletions(-) diff --git a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp index d9f53ecb..ef96cc0f 100644 --- a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp +++ b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp @@ -126,7 +126,7 @@ void CommentSaver::getICGField( std::string file_name ) { so much easier in perl! */ /* find the ICG field */ - ret = regcomp( ®_expr , "(ICG:)" , REG_EXTENDED | REG_ICASE ) ; + regcomp( ®_expr , "(ICG:)" , REG_EXTENDED | REG_ICASE ) ; ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; if ( ret != 0 ) { @@ -136,7 +136,7 @@ void CommentSaver::getICGField( std::string file_name ) { /* find the end of the ICG field */ memset(pmatch , 0 , sizeof(pmatch)) ; - ret = regcomp( ®_expr , "(\\))" , REG_EXTENDED ) ; + regcomp( ®_expr , "(\\))" , REG_EXTENDED ) ; ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; @@ -147,7 +147,7 @@ void CommentSaver::getICGField( std::string file_name ) { /* test for NoComment */ memset(pmatch , 0 , sizeof(pmatch)) ; - ret = regcomp( ®_expr , "(NOCOMMENT)$" , REG_EXTENDED ) ; + regcomp( ®_expr , "(NOCOMMENT)$" , REG_EXTENDED ) ; ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; @@ -157,7 +157,7 @@ void CommentSaver::getICGField( std::string file_name ) { /* test for No */ memset(pmatch , 0 , sizeof(pmatch)) ; - ret = regcomp( ®_expr , "(NO)$" , REG_EXTENDED ) ; + regcomp( ®_expr , "(NO)$" , REG_EXTENDED ) ; ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; @@ -208,7 +208,7 @@ std::set< std::string > CommentSaver::getIgnoreTypes( std::string file_name ) { start += strlen("trick_exclude_typename") ; std::string temp_str = th_str.substr(start) ; memset(pmatch , 0 , sizeof(pmatch)) ; - ret = regcomp( ®_expr , "^\\s*\\{\\s*(\\S+)\\s*\\}" , REG_EXTENDED ) ; + regcomp( ®_expr , "^\\s*\\{\\s*(\\S+)\\s*\\}" , REG_EXTENDED ) ; ret = regexec( ®_expr , temp_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; if ( ret == 0 ) { @@ -230,7 +230,7 @@ std::set< std::string > CommentSaver::getIgnoreTypes( std::string file_name ) { so much easier in perl! */ /* find the start of the ICG_IGNORE_TYPES field */ - ret = regcomp( ®_expr , "(ICG[ _]IGNORE[ _]TYPE(S)?:)" , REG_EXTENDED | REG_ICASE ) ; + regcomp( ®_expr , "(ICG[ _]IGNORE[ _]TYPE(S)?:)" , REG_EXTENDED | REG_ICASE ) ; ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; if ( ret != 0 ) { @@ -240,7 +240,7 @@ std::set< std::string > CommentSaver::getIgnoreTypes( std::string file_name ) { /* find the end of the ICG_IGNORE_TYPES field */ memset(pmatch , 0 , sizeof(pmatch)) ; - ret = regcomp( ®_expr , "(\\)\\s*\\))" , REG_EXTENDED ) ; + regcomp( ®_expr , "(\\)\\s*\\))" , REG_EXTENDED ) ; ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; if ( ret != 0 ) { diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp index 6ff65d7b..eaf5c59a 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp @@ -16,6 +16,7 @@ #include "trick/map_trick_units_to_udunits.hh" extern llvm::cl::opt< bool > units_truth_is_scary ; +extern llvm::cl::opt< int > debug_level ; static ut_system * get_u_system() { @@ -85,20 +86,18 @@ std::string FieldDescription::get_regex_field(std::string input , const char * e regex_t reg_expr ; regmatch_t pmatch[10] ; memset(pmatch , 0 , sizeof(pmatch)) ; - ret = regcomp( ®_expr , expr , REG_EXTENDED ) ; - //std::cout << "regcomp ret = " << ret << std::endl ; + regcomp( ®_expr , expr , REG_EXTENDED ) ; ret = regexec( ®_expr , input.c_str() , 10 , pmatch , 0 ) ; - //std::cout << "regexec ret = " << ret << std::endl ; regfree(®_expr) ; if ( ret == 0 ) { - //std::cout << "pmatch range = " << pmatch[index].rm_so << " " << pmatch[index].rm_eo << std::endl ; + if(debug_level >= 4) std::cout << "pmatch range = " << pmatch[index].rm_so << " " << pmatch[index].rm_eo << std::endl ; if ( pmatch[index].rm_so != -1 ) { return input.substr(pmatch[index].rm_so , pmatch[index].rm_eo - pmatch[index].rm_so ) ; } - } else { - //char error_msg[1024] ; - //regerror( ret , ®_expr , (char *)error_msg , 1024 ) ; - //std::cerr << error_msg << std::endl ; + } else if (debug_level >= 4){ + char error_msg[1024] ; + regerror( ret , ®_expr , (char *)error_msg , 1024 ) ; + std::cerr << error_msg << std::endl ; } return std::string() ; } @@ -127,21 +126,21 @@ void FieldDescription::parseComment(std::string comment) { // remove open comment chars comment = get_regex_field(comment , "^(//|/\\*)(.*)" , 2) ; - //std::cout << "1. " << comment << std::endl ; + if(debug_level >= 4) std::cout << "1. " << comment << std::endl ; // remove optional doxygen comment chars // Note: I had to use [ \t\n\r] for \s because the Mac don't understand! comment = get_regex_field(comment , "^((\\*|!)<)?[ \t\n\r]*(.*)" , 3) ; - //std::cout << "2. " << comment << std::endl ; + if(debug_level >= 4) std::cout << "2. " << comment << std::endl ; // remove optional doxygen keyword comment = get_regex_field(comment , "(\\\\[a-zA-Z0-9]+)?[ \t\n\r]*(.*)" , 2) ; - //std::cout << "3. " << comment << std::endl ; + if(debug_level >= 4) std::cout << "3. " << comment << std::endl ; ret_str = get_regex_field(comment , "@?trick_chkpnt_io[\\({]([^\\)}]+)[\\)}]" , 1) ; if ( ! ret_str.empty()) { chkpnt_io = io_map[ret_str] ; - //std::cout << "go for trick_chkpnt_io " << io << std::endl ; + if(debug_level >= 4) std::cout << "go for trick_chkpnt_io " << io << std::endl ; chkpnt_io_found = true ; comment = get_regex_field(comment , "(.*)@?trick_chkpnt_io[\\({]([^\\)}]+)[\\)}]" , 1) + get_regex_field(comment , "@?trick_chkpnt_io[\\({]([^\\)}]+)[\\)}](.*)" , 2) ; @@ -150,7 +149,7 @@ void FieldDescription::parseComment(std::string comment) { ret_str = get_regex_field(comment , "@?trick_io[\\({]([^\\)}]+)[\\)}]" , 1) ; if ( ! ret_str.empty()) { io = io_map[ret_str] ; - //std::cout << "go for trick_io " << io << std::endl ; + if(debug_level >= 4) std::cout << "go for trick_io " << io << std::endl ; io_found = true ; comment = get_regex_field(comment , "(.*)@?trick_io[\\({]([^\\)}]+)[\\)}]" , 1) + get_regex_field(comment , "@?trick_io[\\({]([^\\)}]+)[\\)}](.*)" , 2) ; @@ -200,28 +199,28 @@ void FieldDescription::parseComment(std::string comment) { if ( ! io_found ) { // Note: I had to use [ \t\n\r] for \s because the Mac don't understand! ret_str = get_regex_field(comment , "^[ \t\n\r]*(\\*io|\\*oi|\\*i|\\*o|\\*\\*)" , 1) ; - //std::cout << "3. " << ret_str << std::endl ; + if(debug_level >= 4) std::cout << "3. " << ret_str << std::endl ; if ( ! ret_str.empty()) { io = io_map[ret_str] ; - //std::cout << "stand-alone io " << io << std::endl ; + if(debug_level >= 4) std::cout << "stand-alone io " << io << std::endl ; io_found = true ; comment = get_regex_field(comment , "^[ \t\n\r]*(\\*io|\\*oi|\\*i|\\*o|\\*\\*)[ \t\n\r]*(.*)" , 2) ; } } - //std::cout << "3. " << comment << std::endl ; + if(debug_level >= 4) std::cout << "3. " << comment << std::endl ; if ( ! units_found ) { ret_str = get_regex_field(comment , "^[ \t\n\r]*\\(([^\\)]*)\\)" , 1) ; if ( ! ret_str.empty()) { units = ret_str ; - //std::cout << "stand-alone units " << units << std::endl ; + if(debug_level >= 4) std::cout << "stand-alone units " << units << std::endl ; units_found = true ; comment = get_regex_field(comment , "^[ \t\n\r]*\\(([^\\)]*)\\)(.*)" , 2) ; } else { ret_str = get_regex_field(comment , "^[ \t\n\r]*([^ \t\n\r)]*)" , 1) ; if ( ! ret_str.empty()) { units = ret_str ; - //std::cout << "stand-alone units " << units << " " << comment << std::endl ; + if(debug_level >= 4) std::cout << "stand-alone units " << units << " " << comment << std::endl ; units_found = true ; comment = get_regex_field(comment , "^[ \t\n\r]*([^ \t\n\r)]*)(.*)" , 2) ; } diff --git a/trick_source/codegen/Interface_Code_Gen/Utilities.cpp b/trick_source/codegen/Interface_Code_Gen/Utilities.cpp index bd9d2e0c..4cf40bba 100644 --- a/trick_source/codegen/Interface_Code_Gen/Utilities.cpp +++ b/trick_source/codegen/Interface_Code_Gen/Utilities.cpp @@ -64,16 +64,19 @@ bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation s std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) { clang::FileID fid = ci.getSourceManager().getFileID(sl) ; + std::string file_name; + char* resolved_path; if ( ! fid.isInvalid() ) { const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ; if ( fe != NULL ) { char * resolved_path = almostRealPath( fe->getName() ) ; if ( resolved_path != NULL and hsd.isPathInUserDir(resolved_path)) { - return std::string(resolved_path) ; + file_name.append(resolved_path); } + free(resolved_path); } } - return std::string() ; + return file_name; } #include diff --git a/trick_source/data_products/EQParse/eqparse_evaluate.c b/trick_source/data_products/EQParse/eqparse_evaluate.c index 46eafb16..f20c09fa 100644 --- a/trick_source/data_products/EQParse/eqparse_evaluate.c +++ b/trick_source/data_products/EQParse/eqparse_evaluate.c @@ -20,7 +20,7 @@ double eval(stack * stk, stack1 * no) { stack1 nos = NULL; - double x, y, z; + double x = 0.0, y = 0.0, z = 0.0; char ch; ldiv_t ldivt; while (!empty(*stk)) { @@ -224,7 +224,7 @@ double eval(stack * stk, stack1 * no) nos = push1(nos, z); } } - nos = pop1(nos, &z); + pop1(nos, &z); #ifdef DEBUG printf("\n%lf", z); #endif diff --git a/trick_source/data_products/EQParse/eqparse_funcsub.c b/trick_source/data_products/EQParse/eqparse_funcsub.c index 13c92737..dff07d60 100644 --- a/trick_source/data_products/EQParse/eqparse_funcsub.c +++ b/trick_source/data_products/EQParse/eqparse_funcsub.c @@ -52,8 +52,8 @@ void funcsub(char *str) #ifdef DEBUG printf("\n%s", equation); #endif - len = strlen(equation); comp = 0; + len = strlen(equation); for (test = 0; test < (len - 1); test++) { if ((isalpha(equation[test])) && ((isalpha(equation[test + 1])) @@ -65,7 +65,6 @@ void funcsub(char *str) while (comp == 1) { start = 0; comp = 0; - len = strlen(equation); i = 0; while (i == 0) { if ((isalpha(equation[start])) && @@ -107,7 +106,6 @@ void funcsub(char *str) start = start + offset; temp[tstart] = '('; tstart++; - ch1 = equation[start]; while (ch1 != ',') { if (ch1 == '\0') { /* No second argument found */ diff --git a/trick_source/data_products/EQParse/eqparse_takeinput.c b/trick_source/data_products/EQParse/eqparse_takeinput.c index ef69f0c8..000efaf9 100644 --- a/trick_source/data_products/EQParse/eqparse_takeinput.c +++ b/trick_source/data_products/EQParse/eqparse_takeinput.c @@ -32,7 +32,6 @@ stack takeinput(stack stk, char *equation, double value) if (eqp_errno) { return (NULL); } - i = 0; len = strlen(equation); for (i = 0; i < len; i++) { ch = equation[i]; diff --git a/trick_source/data_products/Log/Csv.cpp b/trick_source/data_products/Log/Csv.cpp index 12dec266..e90aa922 100644 --- a/trick_source/data_products/Log/Csv.cpp +++ b/trick_source/data_products/Log/Csv.cpp @@ -54,7 +54,7 @@ Csv::Csv(char * file_name , char * param_name ) { } else { if ( !strcmp(start_unit + 1,"--") ) { - unitStr_ = strdup(start_unit + 1) ; + unitStr_ = start_unit + 1; } else { unitStr_ = map_trick_units_to_udunits(start_unit + 1) ; } diff --git a/trick_source/data_products/Log/Delta.cpp b/trick_source/data_products/Log/Delta.cpp index 88fcccc8..5e5f6641 100644 --- a/trick_source/data_products/Log/Delta.cpp +++ b/trick_source/data_products/Log/Delta.cpp @@ -53,7 +53,7 @@ int Delta::get( double * time , double * value ) return ret ; } - ret = dsg_.getLastRead(dataStream1_, time, &val1); + dsg_.getLastRead(dataStream1_, time, &val1); ret = dsg_.getLastRead(dataStream2_, time, &val2); *value = val1 - val2 ; @@ -66,7 +66,7 @@ int Delta::peek( double * time , double * value ) int ret ; double val1, val2 ; - ret = dsg_.getLastRead(dataStream1_, time, &val1); + dsg_.getLastRead(dataStream1_, time, &val1); ret = dsg_.getLastRead(dataStream2_, time, &val2); *value = val1 - val2 ; diff --git a/trick_source/data_products/Log/MatLab.cpp b/trick_source/data_products/Log/MatLab.cpp index b222d9a7..8c8c8f8c 100644 --- a/trick_source/data_products/Log/MatLab.cpp +++ b/trick_source/data_products/Log/MatLab.cpp @@ -57,11 +57,11 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) { short version; short magic; int data_type, bytes, field_data_type, field_bytes; - int size, type; + int size = 0, type = 0; int array_type, array_bytes, array_flags[2]; int array_complex, array_class ; int dim_type, dim_bytes, num_dims; - int * dims; + int * dims = nullptr; int name_bytes; char * name, * field_name, * variable_name; int real_type, real_bytes; @@ -166,7 +166,10 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) { } num_dims = dim_bytes / 4; - + // delete dangling pointer + if(dims) { + delete [] dims; + } dims = new int[num_dims]; for (ii = 0; ii < num_dims; ii++) { fread(&dims[ii], 4, 1, fp_) ; @@ -232,12 +235,12 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) { name = new char[strlen(variable_name)]; strcpy(name, variable_name); field_found = true; - delete field_name; - delete variable_name; + delete [] field_name; + delete [] variable_name; break; } - delete field_name; - delete variable_name; + delete [] field_name; + delete [] variable_name; } if (field_found) { @@ -300,7 +303,10 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) { } num_dims = dim_bytes / 4; - + // delete dangling pointer + if(dims) { + delete [] dims; + } dims = new int[num_dims]; for (ii = 0; ii < num_dims; ii++) { fread(&dims[ii], 4, 1, fp_) ; @@ -342,7 +348,7 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) { // Everythig else we skip temp_ptr = new char[field_bytes]; fread(temp_ptr, field_bytes, 1, fp_) ; - delete temp_ptr; + delete [] temp_ptr; } } else { real_bytes = 0; @@ -516,15 +522,15 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) { } if ( !found) { - delete dims; + delete [] dims; } - delete name; + delete [] name; } else { // Everythig else we skip temp_ptr = new char[bytes]; fread(temp_ptr, bytes, 1, fp_) ; - delete temp_ptr; + delete [] temp_ptr; } } } @@ -647,7 +653,7 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) { int array_type, array_bytes, array_flags[2]; int array_complex, array_class; int dim_type, dim_bytes, num_dims; - int * dims; + int * dims = nullptr; int name_bytes; char * name, * field_name, * variable_name; int real_type, real_bytes; @@ -697,6 +703,9 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) { swap = 0; } else if (magic == 0x494d) { swap = 1; + } else { + std::cerr << "ERROR: MatLab.cpp swap magic is invalid, default to byte swap == false" << std::endl; + swap = 0; } param_found = time_found = false; @@ -749,7 +758,10 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) { } num_dims = dim_bytes / 4; - + // delete dangling pointer + if(dims) { + delete [] dims; + } dims = new int[num_dims]; for (ii = 0; ii < num_dims; ii++) { fread(&dims[ii], 4, 1, fp) ; @@ -814,12 +826,12 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) { name = new char[strlen(variable_name)]; strcpy(name, variable_name); field_found = true; - delete field_name; - delete variable_name; + delete [] field_name; + delete [] variable_name; break; } - delete field_name; - delete variable_name; + delete [] field_name; + delete [] variable_name; } if (field_found) { @@ -880,8 +892,8 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) { } } - delete name; - delete dims; + delete [] name; + delete [] dims; if (param_found && time_found) { fclose(fp); @@ -921,7 +933,7 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) { // Everythig else we skip temp_ptr = new char[bytes]; fread(temp_ptr, bytes, 1, fp) ; - delete temp_ptr; + delete [] temp_ptr; } } } diff --git a/trick_source/data_products/Log/MatLab4.cpp b/trick_source/data_products/Log/MatLab4.cpp index b7900c23..e5f9bc5d 100644 --- a/trick_source/data_products/Log/MatLab4.cpp +++ b/trick_source/data_products/Log/MatLab4.cpp @@ -20,7 +20,7 @@ MatLab4::MatLab4(char * file_name , char * param_name , char * time_name ) { int temp ; int endian ; int mat_size ; - int type , size ; + int type = 0, size = 0; int mat_type ; int my_byte_order ; div_t div_result ; @@ -162,7 +162,7 @@ MatLab4::MatLab4(char * file_name , char * param_name , char * time_name ) { time_found = true ; } - delete temp_ptr ; + delete [] temp_ptr ; // skip to next parameter fseek( fp_ , row * column * size * ( 1 + imaginary ) , SEEK_CUR ) ; @@ -364,6 +364,10 @@ int MatLab4LocateParam( char *file_name , char *param_name , char *time_name ) { case 5: size = 1 ; break ; + default : + std::cerr << "Matlab4 " << __FUNCTION__ << "ERROR: invalid matrix size" << std::endl; + size = -1 ; + break ; } fread( &row , 4 , 1 , fp ) ; @@ -395,11 +399,11 @@ int MatLab4LocateParam( char *file_name , char *param_name , char *time_name ) { if ( param_found && time_found ) { fclose(fp) ; - delete temp_ptr ; + delete[] temp_ptr ; return(1) ; } - delete temp_ptr ; + delete[] temp_ptr ; // skip to next parameter fseek( fp , row * column * size * ( 1 + imaginary ) , SEEK_CUR ) ; diff --git a/trick_source/data_products/Log/TrickBinary.cpp b/trick_source/data_products/Log/TrickBinary.cpp index 0220d754..1688f44e 100644 --- a/trick_source/data_products/Log/TrickBinary.cpp +++ b/trick_source/data_products/Log/TrickBinary.cpp @@ -158,7 +158,7 @@ TrickBinary::TrickBinary(char * file_name , char * param_name ) { if ( ! strcmp( name_ptr , param_name )) { if ( !strcmp(units_ptr,"--") ) { - unitStr_ = strdup(units_ptr) ; + unitStr_ = units_ptr ; } else { unitStr_ = map_trick_units_to_udunits(units_ptr) ; } @@ -374,7 +374,7 @@ int TrickBinaryReadByteOrder( FILE* fp ) { const int file_type_len = 10 ; char file_type[file_type_len + 1] ; int my_byte_order ; - int swap ; + int swap = 0; memset(file_type, 0 , 10 ) ; fread(file_type , file_type_len , 1 , fp ) ; @@ -581,6 +581,6 @@ int TrickBinaryLocateParam( const char * file_name , const char * param_name ) { for ( ii = 0 ; ii < num_vars ; ii++ ) { delete[] var_names[ii] ; } - + delete[] var_names; return(found) ; } diff --git a/trick_source/data_products/Log/log.cpp b/trick_source/data_products/Log/log.cpp index 87cfba37..96ed8f59 100644 --- a/trick_source/data_products/Log/log.cpp +++ b/trick_source/data_products/Log/log.cpp @@ -329,7 +329,6 @@ int LogData::countNumBinaryFiles(char *pathToBinaryData) fprintf(stderr, "Couldn't open \"%s\" for reading. \n", pathToBinaryData); fprintf(stderr, "Maybe LogGroup Constructor not called.\n"); - closedir(dirp); exit(-1); } @@ -391,9 +390,10 @@ int LogData::openCurrBinaryFile() // Do sanity check on file if (access(file, F_OK | R_OK) == -1) { - printf("ERROR: Search for parameter exhausted." + fprintf(stderr, "ERROR: Search for parameter exhausted." " Or \"%s\" is not readable or doesn't exist. \n", file); + delete [] file; return(-1); } // Close previous binary file if not first file to open @@ -509,7 +509,10 @@ int LogData::getSizeRecord() for (i = 0; i < nVars_; i++) { sizeRec = sizeRec + vars[i]->getSize(); } - + if(sizeRec <= 0) { + std::cerr << "ERROR: LogData::getSizeRecord() is zero or negative, may cause divide-by-zero. Exiting." << std::endl; + exit(-1); + } return (sizeRec); } @@ -571,7 +574,7 @@ char *LogData::getNextRecord() if (currBinExtension_ < nBinFiles_) { // Open up next bin file, and get first rec openCurrBinaryFile(); - ret = fread(currRecord_, sr, 1, fp_); + fread(currRecord_, sr, 1, fp_); return (currRecord_); } else { // We are at end of log data (no more recs) @@ -1313,8 +1316,11 @@ int LogGroup::getValueAtTime( const char *paramName, // Get the value at time rr = log[yLogIdx]->getValueAtTime(tIdx, time, yIdx, &vv) ; - *value = vv ; - + // If value with timestamp found + if(rr > 0){ + *value = vv ; + } + return(rr); } @@ -1471,7 +1477,6 @@ int LogGroup::getHeaders() fprintf(stderr, "ERROR: Couldn't open \"%s\" for reading. \n", pathToBinaryData_); fprintf(stderr, "Maybe LogGroup constructer wasn't done. \n"); - closedir(dirp); exit(-1); } // Count num headers, and max file name length in RUN dir diff --git a/trick_source/data_products/Log/parseLogHeader.cpp b/trick_source/data_products/Log/parseLogHeader.cpp index 5b15a20e..05056781 100644 --- a/trick_source/data_products/Log/parseLogHeader.cpp +++ b/trick_source/data_products/Log/parseLogHeader.cpp @@ -17,6 +17,19 @@ #include "trick/units_conv.h" #include "trick/map_trick_units_to_udunits.hh" +// index labels for char arrays +enum strIndex { + LINE, + STR1, + STR2, + STR3, + STR4, + NUM_STR +}; + +// helper function to free memory before successful or unsuccessful return +void shutdown(FILE*, char**, char*); + /* A private function for parsing log header files. * This is responsible for initialize the Log classes as well */ @@ -25,17 +38,13 @@ int LogGroup::parseLogHeaders() int nVars; int lineNum; - char *line; - char *str1; - char *str2; - char *str3; - char *str4; + char** strs = new char*[NUM_STR]; char *headerName; int i; int headerSize; int len; - LogData *currLogData; + LogData *currLogData = 0; Var *currVar; @@ -54,6 +63,8 @@ int LogGroup::parseLogHeaders() fprintf(stderr, "\nERROR:\nCouldn't open file \"%s\" \n", headerName); + delete[] strs; + delete[] headerName; return (-1); } // Allocate strings, we know that buffers can't be @@ -63,15 +74,13 @@ int LogGroup::parseLogHeaders() fseek(fp_, 0, SEEK_END); headerSize = ftell(fp_); ::rewind(fp_); - line = new char[headerSize + 1]; // Not sure about +1 :) - str1 = new char[headerSize + 1]; - str2 = new char[headerSize + 1]; - str3 = new char[headerSize + 1]; - str4 = new char[headerSize + 1]; + for(int i = 0; i < NUM_STR; i++){ + strs[i] = new char[headerSize + 1]; // Not sure about +1 :) + } // Parse rest of file lineNum = 0; - while (fgets(line, headerSize, fp_) != NULL) { + while (fgets(strs[LINE], headerSize, fp_) != NULL) { lineNum++; @@ -79,10 +88,10 @@ int LogGroup::parseLogHeaders() or byte_order is [lit|big]_endian */ - if ( sscanf(line, "%s %s %s %s", str1, str2, str3, str4) == 4 ) { + if ( sscanf(strs[LINE], "%s %s %s %s", strs[STR1], strs[STR2], strs[STR3], strs[STR4]) == 4 ) { // Byte order statement and top of a log group? - if (!strcmp(str2, "byte_order")) { + if (!strcmp(strs[STR2], "byte_order")) { LogData *ld = new LogData; log.push_back(ld); @@ -90,10 +99,10 @@ int LogGroup::parseLogHeaders() nGroups_++; // New binary file - currLogData->setBinaryFileName(str1); + currLogData->setBinaryFileName(strs[STR1]); // Set byte order - if (!strcmp(str4, "big_endian")) { + if (!strcmp(strs[STR4], "big_endian")) { currLogData->dataByteOrder = 1; } else { currLogData->dataByteOrder = 0; @@ -102,7 +111,7 @@ int LogGroup::parseLogHeaders() continue; } // Check for binary file name mismatches - if (strcmp(str1, currLogData->getBinaryFileName())) { + if (currLogData && strcmp(strs[STR1], currLogData->getBinaryFileName())) { printf("ERROR: Parsing log header \"%s\".\n" " Line %d. Binary file name " "mismatch with \"%s\".\n" @@ -110,6 +119,7 @@ int LogGroup::parseLogHeaders() "specification.\n\n", headerName, lineNum, currLogData->getBinaryFileName()); + shutdown(fp_, strs, headerName); return (-1); } // New variable @@ -121,11 +131,12 @@ int LogGroup::parseLogHeaders() currLogData->setNumVars(nVars); // Set Type - if (currVar->setType(str2) < 0) { + if (currVar->setType(strs[STR2]) < 0) { printf("ERROR: In log header \"%s\".\n" " Line %d. Type \"%s\" is " "not supported.\n", - headerName, lineNum, str2); + headerName, lineNum, strs[STR2]); + shutdown(fp_, strs, headerName); return (-1); } @@ -134,43 +145,47 @@ int LogGroup::parseLogHeaders() { char new_units_spec[100]; new_units_spec[0] = 0; - if ( convert_units_spec (str3, new_units_spec) != 0 ) { - printf (" ERROR: Attempt to convert old units-spec, \"%s\" failed.\n\n",str3); + if ( convert_units_spec (strs[STR3], new_units_spec) != 0 ) { + printf (" ERROR: Attempt to convert old units-spec, \"%s\" failed.\n\n",strs[STR3]); + shutdown(fp_, strs, headerName); + return (-1); } - delete [] str3; + delete [] strs[STR3]; len = strlen(new_units_spec); - str3 = new char[len + 1] ; - strcpy(str3, new_units_spec); + strs[STR3] = new char[len + 1] ; + strcpy(strs[STR3], new_units_spec); } // Initialize Unit class - if ( ! strcmp(str3,"--")) { - currVar->setUnit(str3); + if ( ! strcmp(strs[STR3],"--")) { + currVar->setUnit(strs[STR3]); } else { - currVar->setUnit(map_trick_units_to_udunits(str3)); + currVar->setUnit(map_trick_units_to_udunits(strs[STR3])); } // Set Var Name - currVar->setVarName(str4) ; + currVar->setVarName(strs[STR4]) ; if (currVar->getSize() < 0) { printf("ERROR: In log header \"%s\".\n" " Line %d. Problem with var " "name \"%s\" . \n", - headerName, lineNum, str4); + headerName, lineNum, strs[STR4]); + shutdown(fp_, strs, headerName); return (-1); } } } - - fclose(fp_); - delete[]line; - delete[]str1; - delete[]str2; - delete[]str3; - delete[]str4; - delete[]headerName; + shutdown(fp_, strs, headerName); } - + delete[] strs; return 1; } + +void shutdown (FILE* fp_, char** strs, char* headerName) { + fclose(fp_); + for(int i = 0; i < NUM_STR; i++) { + delete[] strs[i]; + } + delete[] headerName; +} diff --git a/trick_source/data_products/Var/var.cpp b/trick_source/data_products/Var/var.cpp index b89dfb67..d7da0ff1 100644 --- a/trick_source/data_products/Var/var.cpp +++ b/trick_source/data_products/Var/var.cpp @@ -466,6 +466,7 @@ int Var::getDimOffset( const char* param ) { if ( offset < 0 ) { fprintf(stderr, "ERROR: Integer overflow " "calculating offset!\n"); + VAR_DELETE; return(-1); } } @@ -656,12 +657,13 @@ int Var::calcNumDimensions() { if ( varName_[i] == ']' ) { cerr << "ERROR: Missing open bracket in" << varName_ << endl ; + delete[] dim1 ; + delete[] dim2 ; return( -1 ); } if ( varName_[i] == '[' ) { - j = 0; while ( varName_[i] != ']' ) { i++ ; @@ -670,6 +672,8 @@ int Var::calcNumDimensions() { if ( i == stringLen ) { cerr << "ERROR: Missing close bracket in" << varName_ << endl ; + delete[] dim1 ; + delete[] dim2 ; return( -1 ) ; } @@ -686,11 +690,15 @@ int Var::calcNumDimensions() { cerr << "ERROR: Missing close " << "bracket in " << varName_ << endl ; + delete[] dim1 ; + delete[] dim2 ; return( -1 ) ; } if ( j > 7 ) { printf("ERROR: Dimension spec " "too long.\n"); + delete[] dim1 ; + delete[] dim2 ; return( -1 ) ; } } @@ -715,6 +723,8 @@ int Var::calcNumDimensions() { << " in " << varName_ << endl ; + delete[] dim1 ; + delete[] dim2 ; return( -1 ) ; } if ( j > 7 ) { @@ -723,6 +733,8 @@ int Var::calcNumDimensions() { << "in " << varName_ << endl ; + delete[] dim1 ; + delete[] dim2 ; return( -1 ) ; } @@ -738,6 +750,8 @@ int Var::calcNumDimensions() { cerr << "ERROR: Dimension has syntax " << "error with " << varName_ << endl ; + delete[] dim1 ; + delete[] dim2 ; return( -1 ) ; } } @@ -746,6 +760,8 @@ int Var::calcNumDimensions() { cerr << "ERROR: Bad syntax in dimension " << "specification for " << varName_ << endl ; + delete[] dim1 ; + delete[] dim2 ; return( -1 ); } diff --git a/trick_source/data_products/makefile b/trick_source/data_products/makefile index f9514b33..6c82f872 100644 --- a/trick_source/data_products/makefile +++ b/trick_source/data_products/makefile @@ -4,6 +4,8 @@ TRICK_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))../..) +TRICK_CXXFLAGS += -std=c++11 + include ${TRICK_HOME}/share/trick/makefiles/Makefile.common LIB_DIR = lib_${TRICK_HOST_CPU} diff --git a/trick_source/er7_utils/integration/rk2_midpoint/src/rk2_midpoint_second_order_ode_integrator.cc b/trick_source/er7_utils/integration/rk2_midpoint/src/rk2_midpoint_second_order_ode_integrator.cc index b0928404..f29ff218 100644 --- a/trick_source/er7_utils/integration/rk2_midpoint/src/rk2_midpoint_second_order_ode_integrator.cc +++ b/trick_source/er7_utils/integration/rk2_midpoint/src/rk2_midpoint_second_order_ode_integrator.cc @@ -315,6 +315,7 @@ RK2MidpointGeneralizedStepSecondOrderODEIntegrator::integrate ( step_factor = 1.0; break; + default: step_factor = 1.0; break; } diff --git a/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp b/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp index 8fc9f126..937e2957 100644 --- a/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp +++ b/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp @@ -259,6 +259,10 @@ static char *getCompositeSubReference( // Calculate the array indices for the right-side. for (j = num_fixed_dims - 1; j >= 0; j--) { size *= A[i].index[j].size; + if(!size) { + std::cerr << "Checkpoint Agent " << __FUNCTION__ << " ERROR: divide by zero during array indices calculation" << std::endl; + return NULL; + } my_index[j] = (int) ((offset % size) / last_size); offset -= last_size * my_index[j]; last_size = size; @@ -613,8 +617,9 @@ void Trick::ClassicCheckPointAgent::write_singleton( std::ostream& chkpnt_os, vo src_addr = (char*)address + offset * sizeof(short); value = *(short*)src_addr; } else { - std::cerr << __FUNCTION__ << " enumeration size error." << std::endl; + std::cerr << __FUNCTION__ << ": enumeration size error." << std::endl; std::cerr.flush(); + value = -1; } enum_attr = (ENUM_ATTR*)attr->attr; diff --git a/trick_source/sim_services/CheckPointAgent/PythonPrint.cpp b/trick_source/sim_services/CheckPointAgent/PythonPrint.cpp index a78393e0..ed529875 100644 --- a/trick_source/sim_services/CheckPointAgent/PythonPrint.cpp +++ b/trick_source/sim_services/CheckPointAgent/PythonPrint.cpp @@ -121,6 +121,7 @@ void Trick::PythonPrint::write_singleton( std::ostream& chkpnt_os, void* address } else { std::cerr << __FUNCTION__ << " enumeration size error." << std::endl; std::cerr.flush(); + value = -1; } enum_attr = (ENUM_ATTR*)attr->attr; diff --git a/trick_source/sim_services/DataRecord/DataRecordGroup.cpp b/trick_source/sim_services/DataRecord/DataRecordGroup.cpp index 375f6ad2..ad16655a 100644 --- a/trick_source/sim_services/DataRecord/DataRecordGroup.cpp +++ b/trick_source/sim_services/DataRecord/DataRecordGroup.cpp @@ -393,7 +393,7 @@ int Trick::DataRecordGroup::init() { drb->ref_searched = true ; } - ret = write_header() ; + write_header() ; // call format specific initialization to open destination and write header ret = format_specific_init() ; diff --git a/trick_source/sim_services/InputProcessor/IPPython.cpp b/trick_source/sim_services/InputProcessor/IPPython.cpp index f940361f..98408a4c 100644 --- a/trick_source/sim_services/InputProcessor/IPPython.cpp +++ b/trick_source/sim_services/InputProcessor/IPPython.cpp @@ -129,7 +129,7 @@ int Trick::IPPython::init() { /* Read and parse the input file. */ if ( verify_input ) { - ret = PyRun_SimpleString("sys.settrace(trick.traceit)") ; + PyRun_SimpleString("sys.settrace(trick.traceit)") ; } if ( (ret = PyRun_SimpleFile(input_fp, input_file.c_str())) != 0 ) { diff --git a/trick_source/sim_services/JITInputFile/JITInputFile.cpp b/trick_source/sim_services/JITInputFile/JITInputFile.cpp index 289f97bc..9d57bc98 100644 --- a/trick_source/sim_services/JITInputFile/JITInputFile.cpp +++ b/trick_source/sim_services/JITInputFile/JITInputFile.cpp @@ -207,12 +207,13 @@ int Trick::JITInputFile::run(std::string file_name , std::string run_function ) if ( call_me == NULL ) { std::string error_message = "JITInputfile could not find function " + run_function ; exec_terminate_with_return(-1 , __FILE__ , __LINE__ , error_message.c_str() ) ; - } - + } else { // We found the function, call it! ret = (*call_me)() ; return ret ; + + } } /** diff --git a/trick_source/sim_services/JSONVariableServer/JSONVariableServerThread.cpp b/trick_source/sim_services/JSONVariableServer/JSONVariableServerThread.cpp index 301453b9..d9b37390 100644 --- a/trick_source/sim_services/JSONVariableServer/JSONVariableServerThread.cpp +++ b/trick_source/sim_services/JSONVariableServer/JSONVariableServerThread.cpp @@ -34,7 +34,6 @@ Trick::JSONVariableServerThread::JSONVariableServerThread(TCDevice * listen_dev) */ Trick::JSONVariableServerThread::~JSONVariableServerThread() { delete [] incoming_msg ; - delete this ; } /* diff --git a/trick_source/sim_services/MonteCarlo/Makefile b/trick_source/sim_services/MonteCarlo/Makefile index a7b54f53..ce3988ae 100644 --- a/trick_source/sim_services/MonteCarlo/Makefile +++ b/trick_source/sim_services/MonteCarlo/Makefile @@ -4,6 +4,8 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.tricklib -include Makefile_deps +TRICK_CXXFLAGS += -std=c++11 + ifeq ($(HAVE_GSL),1) TRICK_CXXFLAGS += -D_HAVE_GSL ifneq ($(GSL_HOME),/usr) diff --git a/trick_source/sim_services/MonteCarlo/MonteVarFile.cpp b/trick_source/sim_services/MonteCarlo/MonteVarFile.cpp index 660e32fd..0ec9ed86 100644 --- a/trick_source/sim_services/MonteCarlo/MonteVarFile.cpp +++ b/trick_source/sim_services/MonteCarlo/MonteVarFile.cpp @@ -77,6 +77,9 @@ std::string Trick::MonteVarFile::get_next_value() { } // Get the next value. + if(temp_str) { + free(temp_str); + } temp_str = strdup(line.c_str()); token = strtok(temp_str, " \t"); @@ -94,8 +97,12 @@ std::string Trick::MonteVarFile::get_next_value() { ss << name << " = " << token; else ss << name << " = " << "trick.attach_units(\"" << unit << "\", " << token << ")"; - + if(temp_str) { + free(temp_str); + temp_str = nullptr; + } return ss.str(); + } char string[100]; sprintf(string, "Trick:MonteVarFile the input file \"%s\" is not open for reading", file_name.c_str()); diff --git a/trick_source/sim_services/MonteCarlo/test/Makefile b/trick_source/sim_services/MonteCarlo/test/Makefile index 6585b30c..da7e0a1c 100644 --- a/trick_source/sim_services/MonteCarlo/test/Makefile +++ b/trick_source/sim_services/MonteCarlo/test/Makefile @@ -8,7 +8,7 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common # Flags passed to the preprocessor. -TRICK_CXXFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -DGTEST_HAS_TR1_TUPLE=0 +TRICK_CXXFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -DGTEST_HAS_TR1_TUPLE=0 -std=c++11 TRICK_LIBS = -L${TRICK_LIB_DIR} -ltrick -ltrick_pyip -ltrick_comm -ltrick_math -ltrick_mm -ltrick_units TRICK_EXEC_LINK_LIBS += -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lgtest_main diff --git a/trick_source/sim_services/VariableServer/VariableServerListenThread.cpp b/trick_source/sim_services/VariableServer/VariableServerListenThread.cpp index ed4fd5c3..06d25df1 100644 --- a/trick_source/sim_services/VariableServer/VariableServerListenThread.cpp +++ b/trick_source/sim_services/VariableServer/VariableServerListenThread.cpp @@ -116,7 +116,7 @@ void * Trick::VariableServerListenThread::thread_body() { std::string version; char * user_name ; - int mcast_socket ; + int mcast_socket = 0; struct sockaddr_in mcast_addr ; struct sockaddr_in mcast_addr_legacy ; @@ -177,17 +177,14 @@ void * Trick::VariableServerListenThread::thread_body() { vst->create_thread() ; vst->wait_for_accept() ; pthread_mutex_unlock(&restart_pause) ; - } else { - if ( broadcast ) { - sprintf(buf1 , "%s\t%hu\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%hu\n" , listen_dev.hostname , (unsigned short)listen_dev.port , - user_name , (int)getpid() , command_line_args_get_default_dir() , command_line_args_get_cmdline_name() , - command_line_args_get_input_file() , version.c_str() , user_tag.c_str(), (unsigned short)listen_dev.port ) ; + } else if ( broadcast ) { + sprintf(buf1 , "%s\t%hu\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%hu\n" , listen_dev.hostname , (unsigned short)listen_dev.port , + user_name , (int)getpid() , command_line_args_get_default_dir() , command_line_args_get_cmdline_name() , + command_line_args_get_input_file() , version.c_str() , user_tag.c_str(), (unsigned short)listen_dev.port ) ; - sendto(mcast_socket , buf1 , strlen(buf1) , 0 , (struct sockaddr *)&mcast_addr , (socklen_t)sizeof(mcast_addr)) ; - sendto(mcast_socket , buf1 , strlen(buf1) , 0 , (struct sockaddr *)&mcast_addr_legacy , (socklen_t)sizeof(mcast_addr)) ; - } + sendto(mcast_socket , buf1 , strlen(buf1) , 0 , (struct sockaddr *)&mcast_addr , (socklen_t)sizeof(mcast_addr)) ; + sendto(mcast_socket , buf1 , strlen(buf1) , 0 , (struct sockaddr *)&mcast_addr_legacy , (socklen_t)sizeof(mcast_addr)) ; } - } return NULL ; diff --git a/trick_source/sim_services/VariableServer/VariableServerThread_copy_sim_data.cpp b/trick_source/sim_services/VariableServer/VariableServerThread_copy_sim_data.cpp index f491b44e..35c36d3b 100644 --- a/trick_source/sim_services/VariableServer/VariableServerThread_copy_sim_data.cpp +++ b/trick_source/sim_services/VariableServer/VariableServerThread_copy_sim_data.cpp @@ -86,8 +86,9 @@ int Trick::VariableServerThread::copy_sim_data() { curr_var->size = wcslen((wchar_t *)curr_var->address) * sizeof(wchar_t); } } - - memcpy( curr_var->buffer_in , curr_var->address , curr_var->size ) ; + if(curr_var->address != NULL) { + memcpy( curr_var->buffer_in , curr_var->address , curr_var->size ) ; + } } // Indicate that sim data has been written and is now ready in the buffer_in's of the vars variable list. diff --git a/trick_source/sim_services/VariableServer/VariableServerThread_loop.cpp b/trick_source/sim_services/VariableServer/VariableServerThread_loop.cpp index bf7fe60d..24c82b52 100644 --- a/trick_source/sim_services/VariableServer/VariableServerThread_loop.cpp +++ b/trick_source/sim_services/VariableServer/VariableServerThread_loop.cpp @@ -36,7 +36,7 @@ void * Trick::VariableServerThread::thread_body() { vs->add_vst( pthread_self() , this ) ; if ( listen_dev->socket_type == SOCK_STREAM ) { - ret = tc_accept(listen_dev, &connection); + tc_accept(listen_dev, &connection); tc_blockio(&connection, TC_COMM_ALL_OR_NOTHING); } connection_accepted = true ; @@ -141,7 +141,7 @@ void * Trick::VariableServerThread::thread_body() { } if ( copy_mode == VS_COPY_ASYNC ) { - ret = copy_sim_data() ; + copy_sim_data() ; } if ( (write_mode == VS_WRITE_ASYNC) or diff --git a/trick_source/trick_utils/comm/src/tc_init_mcast_client.c b/trick_source/trick_utils/comm/src/tc_init_mcast_client.c index d87bf951..d0cb6c8f 100644 --- a/trick_source/trick_utils/comm/src/tc_init_mcast_client.c +++ b/trick_source/trick_utils/comm/src/tc_init_mcast_client.c @@ -23,7 +23,7 @@ int tc_init_mcast_client(TCDevice * mcast_client_device) { if (!mcast_client_device) { - trick_error_report(mcast_client_device->error_handler, + trick_error_report(NULL, TRICK_ERROR_ALERT, __FILE__, __LINE__, "mcast device is null."); return (-1); } diff --git a/trick_source/trick_utils/comm/src/tc_init_mcast_server.c b/trick_source/trick_utils/comm/src/tc_init_mcast_server.c index 978a6876..788e2a09 100644 --- a/trick_source/trick_utils/comm/src/tc_init_mcast_server.c +++ b/trick_source/trick_utils/comm/src/tc_init_mcast_server.c @@ -26,7 +26,7 @@ int tc_init_mcast_server(TCDevice * mcast_server_device) const unsigned int yes = 1; if (!mcast_server_device) { - trick_error_report(mcast_server_device->error_handler, + trick_error_report(NULL, TRICK_ERROR_ALERT, __FILE__, __LINE__, "mcast device is null."); return (-1); } diff --git a/trick_source/trick_utils/comm/src/tc_init_udp_client.c b/trick_source/trick_utils/comm/src/tc_init_udp_client.c index b67e536c..3c97b57b 100644 --- a/trick_source/trick_utils/comm/src/tc_init_udp_client.c +++ b/trick_source/trick_utils/comm/src/tc_init_udp_client.c @@ -37,7 +37,7 @@ int tc_init_udp_client(TCDevice * udp_client_device) memset(&sockin, 0 , sizeof(struct sockaddr_in)) ; if (!udp_client_device) { - trick_error_report(udp_client_device->error_handler, + trick_error_report(NULL, TRICK_ERROR_ALERT, __FILE__, __LINE__, "UDP device is null."); return (-1); } diff --git a/trick_source/trick_utils/comm/src/tc_init_udp_server.c b/trick_source/trick_utils/comm/src/tc_init_udp_server.c index 0862c2cd..f8654ec3 100644 --- a/trick_source/trick_utils/comm/src/tc_init_udp_server.c +++ b/trick_source/trick_utils/comm/src/tc_init_udp_server.c @@ -30,7 +30,7 @@ int tc_init_udp_server( /* RETURN: -- 0 for success */ unsigned int yes = 1; if (!udp_server_device) { - trick_error_report(udp_server_device->error_handler, + trick_error_report(NULL, TRICK_ERROR_ALERT, __FILE__, __LINE__, "UDP device is null."); return (-1); } diff --git a/trick_source/trick_utils/shm/src/tsm_disconnect.c b/trick_source/trick_utils/shm/src/tsm_disconnect.c index 52a6aaf4..258e4dff 100644 --- a/trick_source/trick_utils/shm/src/tsm_disconnect.c +++ b/trick_source/trick_utils/shm/src/tsm_disconnect.c @@ -10,8 +10,6 @@ int tsm_disconnect(TSMDevice * shm_device) { int ret; - ret = TSM_SUCCESS; - // if we had a read/write lock, destroy it first if (shm_device->rwlock_addr != NULL) { ret = pthread_rwlockattr_destroy(&shm_device->rwlattr); diff --git a/trick_source/trick_utils/trick_adt/src/MapStrToPtr.c b/trick_source/trick_utils/trick_adt/src/MapStrToPtr.c index 073ced5e..6ed1ffe2 100644 --- a/trick_source/trick_utils/trick_adt/src/MapStrToPtr.c +++ b/trick_source/trick_utils/trick_adt/src/MapStrToPtr.c @@ -26,14 +26,15 @@ void DeleteTblEntry(TBLENTRY * entry) /* create an iterator */ StrMapIterator *SMI_Create(MapStrToPtr * pTable) { - StrMapIterator *pIter = (StrMapIterator *) malloc(sizeof(StrMapIterator)); - + StrMapIterator *pIter; if (pTable == NULL) { fprintf(stderr, "Table is NULL"); return NULL; } + pIter = (StrMapIterator *) malloc(sizeof(StrMapIterator)); + pIter->m_pTable = pTable; pIter->m_Index = 0; /* set the current index of the list array to 0 */ pIter->m_ListPos = NULL; /* set the position reference to null indicating there is not a current element */ diff --git a/trick_source/trick_utils/trick_adt/src/bst.c b/trick_source/trick_utils/trick_adt/src/bst.c index d2a500dc..b92a33d8 100644 --- a/trick_source/trick_utils/trick_adt/src/bst.c +++ b/trick_source/trick_utils/trick_adt/src/bst.c @@ -11,8 +11,12 @@ bstNode *bstFind(void *info, BST * bst) { bstNode *current; - if (bst == NULL && info == NULL) { - fprintf(stderr, "Queue is empty"); + if (bst == NULL) { + fprintf(stderr, "bst is not allocated"); + return NULL; + } + if (info == NULL) { + fprintf(stderr, "info is invalid pointer"); return NULL; } @@ -97,8 +101,12 @@ void *bstDelete(bstNode * node, BST * bst) bstNode **parentspointer; - if (node == NULL && bst == NULL) { - fprintf(stderr, "Queue is empty"); + if (bst == NULL) { + fprintf(stderr, "bst is not allocated"); + return NULL; + } + if (node == NULL) { + fprintf(stderr, "node is invalid pointer"); return NULL; } @@ -107,7 +115,7 @@ void *bstDelete(bstNode * node, BST * bst) return (node); } bst->nodes--; /* decrement the node counter */ - if (node->parent != NULL) { /* if node is not the root, *//* then get the address of the parent's pointer to node */ + if (node && node->parent != NULL) { /* if node is not the root, *//* then get the address of the parent's pointer to node */ if (node->parent->left == node) parentspointer = &(node->parent->left); else @@ -201,12 +209,16 @@ bstNode *bstInsert(void *info, BST * bst) int done = 0; - if (bst == NULL && info == NULL) { - fprintf(stderr, "Queue is empty"); + if (bst == NULL) { + fprintf(stderr, "bst is not allocated"); + return NULL; + } + if (info == NULL) { + fprintf(stderr, "info is invalid pointer"); return NULL; } - if (!bst->init) { + if (bst && !bst->init) { bstInit(bst); } newNode = (bstNode *) malloc(sizeof(bstNode)); /* allocate memory for the node */