From 77e0e73b3ffa01011e1e90718b6028b8c9b3b814 Mon Sep 17 00:00:00 2001 From: Scott Fennell Date: Tue, 25 Sep 2018 10:41:14 -0500 Subject: [PATCH] various static analyser bug fixes --- .../Interface_Code_Gen/CommentSaver.cpp | 14 +++++----- .../Interface_Code_Gen/FieldDescription.cpp | 2 +- trick_source/data_products/Log/MatLab4.cpp | 2 +- trick_source/data_products/Log/log.cpp | 2 -- .../VariableServerThread_copy_sim_data.cpp | 5 ++-- .../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_source/trick_utils/trick_adt/src/bst.c | 28 +++++++++++++------ 11 files changed, 36 insertions(+), 27 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..7579a5ee 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp @@ -85,7 +85,7 @@ 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 ) ; + regcomp( ®_expr , expr , REG_EXTENDED ) ; //std::cout << "regcomp ret = " << ret << std::endl ; ret = regexec( ®_expr , input.c_str() , 10 , pmatch , 0 ) ; //std::cout << "regexec ret = " << ret << std::endl ; diff --git a/trick_source/data_products/Log/MatLab4.cpp b/trick_source/data_products/Log/MatLab4.cpp index b7900c23..ab5c0053 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, size = 0; int mat_type ; int my_byte_order ; div_t div_result ; diff --git a/trick_source/data_products/Log/log.cpp b/trick_source/data_products/Log/log.cpp index 87cfba37..f1016bc4 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); } @@ -1471,7 +1470,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/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/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/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 */