Skip to content

Commit

Permalink
static codechecker, MARDYN_EXIT
Browse files Browse the repository at this point in the history
  • Loading branch information
amartyads committed Oct 29, 2024
1 parent ce1066d commit ed42fac
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
20 changes: 10 additions & 10 deletions src/parallel/boundaries/BoundaryHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "utils/mardyn_assert.h"

#include <algorithm>
#include <sstream> // for ostringstream

BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType(DimensionUtils::DimensionType dimension) const {
return _boundaries.at(dimension);
Expand All @@ -27,9 +28,9 @@ void BoundaryHandler::setGlobalWallType(DimensionUtils::DimensionType dimension,
if (dimension != DimensionUtils::DimensionType::ERROR)
_boundaries[dimension] = value;
else {
Log::global_log->error() << "DimensionType::ERROR received in BoundaryHandler::setGlobalWallType!!"
<< std::endl;
mardyn_exit(1);
std::ostringstream error_message;
error_message << "DimensionType::ERROR received in BoundaryHandler::setGlobalWallType!!" << std::endl;
MARDYN_EXIT(error_message.str());
}
}

Expand Down Expand Up @@ -130,10 +131,9 @@ void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer *molec
break;
}
default:
Log::global_log->error()
<< "BoundaryType::ERROR received in BoundaryHandler::processGlobalWallLeavingParticles!"
<< std::endl;
mardyn_exit(1);
std::ostringstream error_message;
error_message << "BoundaryType::ERROR received in BoundaryHandler::processGlobalWallLeavingParticles!" << std::endl;
MARDYN_EXIT(error_message.str());
}

Check notice

Code scanning / CodeQL

Long switch case Note

Switch has at least one case that is too long:
REFLECTING (35 lines)
.
}
}
Expand Down Expand Up @@ -169,9 +169,9 @@ void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer *moleculeContaine
break;
}
default:
Log::global_log->error() << "BoundaryType::ERROR received in BoundaryHandler::removeNonPeriodicHalos!"
<< std::endl;
mardyn_exit(1);
std::ostringstream error_message;
error_message << "BoundaryType::ERROR received in BoundaryHandler::removeNonPeriodicHalos!" << std::endl;
MARDYN_EXIT(error_message.str());
}
}
}
14 changes: 7 additions & 7 deletions src/parallel/boundaries/BoundaryUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <algorithm>
#include <cctype>
#include <string>
#include <sstream> // for ostringstream

BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::string &boundary) {
std::string boundaryLowercase(boundary);
Expand All @@ -24,10 +25,9 @@ BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::st
return BoundaryType::REFLECTING;
if (boundaryLowercase.find("out") != std::string::npos)
return BoundaryType::OUTFLOW;
Log::global_log->error() << "Invalid boundary type passed to "
"BoundaryUtils::convertStringToBoundary. Check your input file!"
<< std::endl;
mardyn_exit(1);
std::ostringstream error_message;
error_message << "Invalid boundary type passed to BoundaryUtils::convertStringToBoundary. Check your input file!" << std::endl;
MARDYN_EXIT(error_message.str());
return BoundaryType::ERROR; // warning suppression
}

Expand All @@ -40,9 +40,9 @@ std::string BoundaryUtils::convertBoundaryToString(BoundaryType boundary) {
case BoundaryType::OUTFLOW:
return "outflow";
default:
Log::global_log->error() << "BoundaryType::ERROR received in BoundaryUtils::convertBoundaryToString!"
<< std::endl;
mardyn_exit(1);
std::ostringstream error_message;
error_message << "BoundaryType::ERROR received in BoundaryUtils::convertBoundaryToString!" << std::endl;
MARDYN_EXIT(error_message.str());
}
return "error"; // warning suppression
}
21 changes: 13 additions & 8 deletions src/parallel/boundaries/DimensionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#include "DimensionUtils.h"
#include "utils/Logger.h"
#include "utils/mardyn_assert.h" // for mardyn_exit()
#include "utils/mardyn_assert.h" // for MARDYN_EXIT()

#include <sstream> // for ostringstream

bool DimensionUtils::isDimensionNumericPermissible(int dim) {
// permissible dimensions are {-1, -2, -3, 1, 2, 3}
Expand All @@ -16,9 +18,10 @@ bool DimensionUtils::isDimensionNumericPermissible(int dim) {

DimensionUtils::DimensionType DimensionUtils::convertNumericToDimension(int dim) {
if (!isDimensionNumericPermissible(dim)) {
Log::global_log->error() << "Invalid dimension passed for enum conversion. Received value: " << dim
std::ostringstream error_message;
error_message << "Invalid dimension passed for enum conversion. Received value: " << dim
<< std::endl;
mardyn_exit(1);
MARDYN_EXIT(error_message.str());
return DimensionType::ERROR;
}
switch (dim) {
Expand Down Expand Up @@ -66,9 +69,10 @@ std::string DimensionUtils::convertDimensionToString(DimensionType dimension) {
case DimensionType::NEGZ:
return "-z";
default: // ERROR
Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToString!"
std::ostringstream error_message;
error_message << "DimesionType::ERROR received in DimensionUtils::convertDimensionToString!"
<< std::endl;
mardyn_exit(1);
MARDYN_EXIT(error_message.str());
return "error";
}
}
Expand All @@ -92,9 +96,10 @@ int DimensionUtils::convertDimensionToNumeric(DimensionType dimension) {
case DimensionType::NEGZ:
return -3;
default:
Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToNumeric!"
std::ostringstream error_message;
error_message << "DimesionType::ERROR received in DimensionUtils::convertDimensionToNumeric!"
<< std::endl;
mardyn_exit(1);
MARDYN_EXIT(error_message.str());
return 0;
}
}
Expand All @@ -105,4 +110,4 @@ int DimensionUtils::convertDimensionToNumericAbs(DimensionType dimension) {

int DimensionUtils::convertEnumToLS1DimIndex(DimensionType dimension) {
return convertDimensionToNumericAbs(dimension) - 1;
}
}
2 changes: 1 addition & 1 deletion src/parallel/boundaries/DimensionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ int convertEnumToLS1DimIndex(DimensionType dimension);
*/
inline int findSign(DimensionType dimension) { return ::findSign(convertDimensionToNumeric(dimension)); }

} // namespace DimensionUtils
} // namespace DimensionUtils
14 changes: 9 additions & 5 deletions src/parallel/boundaries/RegionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

#include "RegionUtils.h"
#include "utils/mardyn_assert.h" //for mardyn_exit()
#include "utils/mardyn_assert.h" //for MARDYN_EXIT()

#include <sstream> // for ostringstream

std::tuple<std::array<double, 3>, std::array<double, 3>> RegionUtils::getInnerRegionSlab(
const std::array<double, 3> &givenRegionBegin, const std::array<double, 3> &givenRegionEnd,
Expand Down Expand Up @@ -39,8 +41,9 @@ std::tuple<std::array<double, 3>, std::array<double, 3>> RegionUtils::getInnerRe
break;

default:
Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getInnerRegionSlab" << std::endl;
mardyn_exit(1);
std::ostringstream error_message;
error_message << "DimensionType::ERROR received in RegionUtils::getInnerRegionSlab" << std::endl;
MARDYN_EXIT(error_message.str());
}
return {returnRegionBegin, returnRegionEnd};
}
Expand Down Expand Up @@ -106,8 +109,9 @@ std::tuple<std::array<double, 3>, std::array<double, 3>> RegionUtils::getOuterRe
break;

default:
Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getOuterRegionSlab" << std::endl;
mardyn_exit(1);
std::ostringstream error_message;
error_message << "DimensionType::ERROR received in RegionUtils::getOuterRegionSlab" << std::endl;
MARDYN_EXIT(error_message.str());
}
return std::make_tuple(returnRegionBegin, returnRegionEnd);
}
2 changes: 1 addition & 1 deletion src/parallel/boundaries/RegionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ std::tuple<std::array<double, 3>, std::array<double, 3>> getOuterRegionSlab(
const std::array<double, 3> &givenRegionBegin, const std::array<double, 3> &givenRegionEnd,
DimensionUtils::DimensionType dimension, const std::array<double, 3> &regionWidth);

} // namespace RegionUtils
} // namespace RegionUtils

0 comments on commit ed42fac

Please sign in to comment.