apply corrections to issues reported by static code analysis

This commit is contained in:
Axel Kohlmeyer 2016-10-24 17:12:28 -04:00
parent 477ddaf112
commit 7b89e47a38
4 changed files with 28 additions and 52 deletions

View File

@ -36,7 +36,7 @@ class FixHalt : public Fix {
private: private:
int attribute,operation,eflag,ivar; int attribute,operation,eflag,ivar;
double attvalue,value; double value;
char *idvar; char *idvar;
double bondmax(); double bondmax();

View File

@ -578,34 +578,21 @@ void Region::write_restart(FILE *fp)
int Region::restart(char *buf, int &n) int Region::restart(char *buf, int &n)
{ {
int sizeid = buf[n]; int size = *((int *)(buf+n));
n += sizeof(int); n += sizeof(int);
char *restart_id = new char[sizeid]; if ((size <= 0) || (strcmp(buf+n,id) != 0)) return 0;
for (int i = 0; i < sizeid; i++) n += size;
restart_id[i] = buf[n++];
if (strcmp(restart_id,id) != 0) return 0;
int sizestyle = buf[n]; size = *((int *)(buf+n));
n += sizeof(int); n += sizeof(int);
char *restart_style = new char[sizestyle]; if ((size <= 0) || (strcmp(buf+n,style) != 0)) return 0;
for (int i = 0; i < sizestyle; i++) n += size;
restart_style[i] = buf[n++];
if (strcmp(restart_style,style) != 0) return 0;
int restart_nreg = buf[n]; int restart_nreg = *((int *)(buf+n));
n += sizeof(int); n += sizeof(int);
if (restart_nreg != nregion) return 0; if (restart_nreg != nregion) return 0;
char *rlist = new char[size_restart*sizeof(double)]; memcpy(prev,buf+n,size_restart*sizeof(double));
for (int i = 0; i < size_restart*sizeof(double); i++)
rlist[i] = buf[n++];
for (int i = 0; i < size_restart; i++){
prev[i] = ((double *)rlist)[i];
}
delete [] rlist;
delete [] restart_id;
delete [] restart_style;
return 1; return 1;
} }

View File

@ -323,30 +323,23 @@ void RegIntersect::write_restart(FILE *fp)
int RegIntersect::restart(char *buf, int& n) int RegIntersect::restart(char *buf, int& n)
{ {
int sizeid = buf[n]; int size = *((int *)(buf+n));
n += sizeof(int); n += sizeof(int);
char *restart_id = new char[sizeid]; if ((size <= 0) || (strcmp(buf+n,id) != 0)) return 0;
for (int i = 0; i < sizeid; i++) n += size;
restart_id[i] = buf[n++];
if (strcmp(restart_id,id) != 0) return 0;
int sizestyle = buf[n]; size = *((int *)(buf+n));
n += sizeof(int); n += sizeof(int);
if ((size <= 0) || (strcmp(buf+n,style) != 0)) return 0;
n += size;
char *restart_style = new char[sizestyle]; int restart_nreg = *((int *)(buf+n));
for (int i = 0; i < sizestyle; i++)
restart_style[i] = buf[n++];
if (strcmp(restart_style,style) != 0) return 0;
int restart_nreg = buf[n];
n += sizeof(int); n += sizeof(int);
if (restart_nreg != nregion) return 0; if (restart_nreg != nregion) return 0;
for (int ilist = 0; ilist < nregion; ilist++){ for (int ilist = 0; ilist < nregion; ilist++)
if (!domain->regions[list[ilist]]->restart(buf, n)){ if (!domain->regions[list[ilist]]->restart(buf, n)) return 0;
return 0;
}
}
return 1; return 1;
} }

View File

@ -315,27 +315,23 @@ void RegUnion::write_restart(FILE *fp)
int RegUnion::restart(char *buf, int &n) int RegUnion::restart(char *buf, int &n)
{ {
int sizeid = buf[n]; int size = *((int *)(buf+n));
n += sizeof(int); n += sizeof(int);
char *restart_id = new char[sizeid]; if ((size <= 0) || (strcmp(buf+n,id) != 0)) return 0;
for (int i = 0; i < sizeid; i++) n += size;
restart_id[i] = buf[n++];
if (strcmp(restart_id,id) != 0) return 0;
int sizestyle = buf[n]; size = *((int *)(buf+n));
n += sizeof(int); n += sizeof(int);
char *restart_style = new char[sizestyle]; if ((size <= 0) || (strcmp(buf+n,style) != 0)) return 0;
for (int i = 0; i < sizestyle; i++) n += size;
restart_style[i] = buf[n++];
if (strcmp(restart_style,style) != 0) return 0;
int restart_nreg = buf[n]; int restart_nreg = *((int *)(buf+n));
n += sizeof(int); n += sizeof(int);
if (restart_nreg != nregion) return 0; if (restart_nreg != nregion) return 0;
for (int ilist = 0; ilist < nregion; ilist++){ for (int ilist = 0; ilist < nregion; ilist++)
if (!domain->regions[list[ilist]]->restart(buf, n)) return 0; if (!domain->regions[list[ilist]]->restart(buf, n)) return 0;
}
return 1; return 1;
} }