Skip to content

Commit 5a6fa9a

Browse files
Fix compiler warnings and cppcheck
1 parent 495ea7d commit 5a6fa9a

File tree

8 files changed

+247
-185
lines changed

8 files changed

+247
-185
lines changed

Framework/NexusCpp/src/NeXusFile.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ AttrInfo File::getNextAttr() {
10041004
AttrInfo info;
10051005
info.name = NULL_STR;
10061006
info.length = 0;
1007+
info.type = NXnumtype::BINARY; // junk value that shouldn't be checked for
10071008
return info;
10081009
} else {
10091010
throw Exception("NXgetnextattra failed", status);
@@ -1095,8 +1096,7 @@ void File::getAttr(const std::string &name, std::vector<std::string> &array) {
10951096
int type;
10961097
int rank;
10971098
int dim[NX_MAXRANK];
1098-
NXstatus status = NXgetattrainfo(this->m_file_id, attr_name, &rank, dim, &type);
1099-
if (status != NX_OK) {
1099+
if (NXgetattrainfo(this->m_file_id, attr_name, &rank, dim, &type) != NX_OK) {
11001100
throw Exception("Attribute \"" + name + "\" not found");
11011101
}
11021102

@@ -1107,7 +1107,8 @@ void File::getAttr(const std::string &name, std::vector<std::string> &array) {
11071107
// read data
11081108
std::string sep(", ");
11091109
char *char_data = new char[dim[0] * (dim[1] + sep.size())];
1110-
status = NXgetattra(this->m_file_id, attr_name, char_data);
1110+
if (NXgetattra(this->m_file_id, attr_name, char_data) != NX_OK)
1111+
throw Exception("Could not iterate to next attribute");
11111112

11121113
// split data to strings
11131114
std::string data(char_data);
@@ -1291,10 +1292,14 @@ template <typename NumT> void File::malloc(NumT *&data, const Info &info) {
12911292
if (getType<NumT>() != info.type) {
12921293
throw Exception("Type mismatch in malloc()");
12931294
}
1295+
// cppcheck-suppress cstyleCast
12941296
inner_malloc((void *&)data, info.dims, info.type);
12951297
}
12961298

1297-
template <typename NumT> void File::free(NumT *&data) { inner_free((void *&)data); }
1299+
template <typename NumT> void File::free(NumT *&data) {
1300+
// cppcheck-suppress cstyleCast
1301+
inner_free((void *&)data);
1302+
}
12981303

12991304
} // namespace NeXus
13001305

0 commit comments

Comments
 (0)