scan-build changes

This reverts commit e86027f825.
This commit is contained in:
Scott Fennell 2018-11-06 11:23:12 -06:00
parent e86027f825
commit 21c01a5454
35 changed files with 226 additions and 148 deletions

View File

@ -126,7 +126,7 @@ void CommentSaver::getICGField( std::string file_name ) {
so much easier in perl! */
/* find the ICG field */
ret = regcomp( &reg_expr , "(ICG:)" , REG_EXTENDED | REG_ICASE ) ;
regcomp( &reg_expr , "(ICG:)" , REG_EXTENDED | REG_ICASE ) ;
ret = regexec( &reg_expr , th_str.c_str() , 10 , pmatch , 0 ) ;
regfree(&reg_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( &reg_expr , "(\\))" , REG_EXTENDED ) ;
regcomp( &reg_expr , "(\\))" , REG_EXTENDED ) ;
ret = regexec( &reg_expr , th_str.c_str() , 10 , pmatch , 0 ) ;
regfree(&reg_expr) ;
@ -147,7 +147,7 @@ void CommentSaver::getICGField( std::string file_name ) {
/* test for NoComment */
memset(pmatch , 0 , sizeof(pmatch)) ;
ret = regcomp( &reg_expr , "(NOCOMMENT)$" , REG_EXTENDED ) ;
regcomp( &reg_expr , "(NOCOMMENT)$" , REG_EXTENDED ) ;
ret = regexec( &reg_expr , th_str.c_str() , 10 , pmatch , 0 ) ;
regfree(&reg_expr) ;
@ -157,7 +157,7 @@ void CommentSaver::getICGField( std::string file_name ) {
/* test for No */
memset(pmatch , 0 , sizeof(pmatch)) ;
ret = regcomp( &reg_expr , "(NO)$" , REG_EXTENDED ) ;
regcomp( &reg_expr , "(NO)$" , REG_EXTENDED ) ;
ret = regexec( &reg_expr , th_str.c_str() , 10 , pmatch , 0 ) ;
regfree(&reg_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( &reg_expr , "^\\s*\\{\\s*(\\S+)\\s*\\}" , REG_EXTENDED ) ;
regcomp( &reg_expr , "^\\s*\\{\\s*(\\S+)\\s*\\}" , REG_EXTENDED ) ;
ret = regexec( &reg_expr , temp_str.c_str() , 10 , pmatch , 0 ) ;
regfree(&reg_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( &reg_expr , "(ICG[ _]IGNORE[ _]TYPE(S)?:)" , REG_EXTENDED | REG_ICASE ) ;
regcomp( &reg_expr , "(ICG[ _]IGNORE[ _]TYPE(S)?:)" , REG_EXTENDED | REG_ICASE ) ;
ret = regexec( &reg_expr , th_str.c_str() , 10 , pmatch , 0 ) ;
regfree(&reg_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( &reg_expr , "(\\)\\s*\\))" , REG_EXTENDED ) ;
regcomp( &reg_expr , "(\\)\\s*\\))" , REG_EXTENDED ) ;
ret = regexec( &reg_expr , th_str.c_str() , 10 , pmatch , 0 ) ;
regfree(&reg_expr) ;
if ( ret != 0 ) {

View File

@ -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( &reg_expr , expr , REG_EXTENDED ) ;
//std::cout << "regcomp ret = " << ret << std::endl ;
regcomp( &reg_expr , expr , REG_EXTENDED ) ;
ret = regexec( &reg_expr , input.c_str() , 10 , pmatch , 0 ) ;
//std::cout << "regexec ret = " << ret << std::endl ;
regfree(&reg_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 , &reg_expr , (char *)error_msg , 1024 ) ;
//std::cerr << error_msg << std::endl ;
} else if (debug_level >= 4){
char error_msg[1024] ;
regerror( ret , &reg_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) ;
}

View File

@ -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 <iostream>

View File

@ -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

View File

@ -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 */

View File

@ -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];

View File

@ -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) ;
}

View File

@ -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 ;

View File

@ -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;
}
}
}

View File

@ -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 ) ;

View File

@ -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) ;
}

View File

@ -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,7 +1316,10 @@ 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

View File

@ -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
<log_file_name> 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;
}

View File

@ -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 );
}

View File

@ -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}

View File

@ -315,6 +315,7 @@ RK2MidpointGeneralizedStepSecondOrderODEIntegrator::integrate (
step_factor = 1.0;
break;
default:
step_factor = 1.0;
break;
}

View File

@ -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;

View File

@ -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;

View File

@ -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() ;

View File

@ -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 ) {

View File

@ -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 ;
}
}
/**

View File

@ -34,7 +34,6 @@ Trick::JSONVariableServerThread::JSONVariableServerThread(TCDevice * listen_dev)
*/
Trick::JSONVariableServerThread::~JSONVariableServerThread() {
delete [] incoming_msg ;
delete this ;
}
/*

View File

@ -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)

View File

@ -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());

View File

@ -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

View File

@ -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 ;

View File

@ -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.

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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 */

View File

@ -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 */