diff --git a/commonFiles/error_defs.h b/commonFiles/error_defs.h index 7232e0a5b..8772fb79e 100644 --- a/commonFiles/error_defs.h +++ b/commonFiles/error_defs.h @@ -25,6 +25,7 @@ #define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL #define MULTI_HAVE_DIFFERENT_VALUES 0x4000000000000000ULL #define MULTI_CONFIG_FILE_ERROR 0x2000000000000000ULL +#define MULTI_POS_EXCEEDS_LIST 0x1000000000000000ULL // sls errors #define CRITICAL_ERROR_MASK 0xFFFFFFF diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index a6500e7f9..8f2b3934b 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -340,11 +340,10 @@ std::string multiSlsDetector::getErrorMessage(int& critical, int detPos) { // single if (detPos >= 0) { - // position exceeds multi list size - if (detPos > detectors.size()) { - FILE_LOG(logERROR) << "Position " << detPos << " exceeds list of " << detectors.size(); + + if(isDetectorIndexOutOfBounds()) return retval; - } + slsMask = getErrorMask(); posmin = (unsigned int)detPos; posmax = posmin + 1; @@ -404,14 +403,8 @@ int64_t multiSlsDetector::clearAllErrorMask(int detPos) { // single if (detPos >= 0) { - - // position exceeds multi list size - if (detPos > detectors.size()) { - FILE_LOG(logERROR) << "Position " << detPos << " exceeds list of " << detectors.size(); - setErrorMask(getErrorMask() | MULTI_POS_EXCEEDS_LIST); + if(isDetectorIndexOutOfBounds()) return -1; - } - return detectors[idet]->clearErrorMask(); } @@ -456,12 +449,8 @@ int multiSlsDetector::checkVersionCompatibility(portType t, int detPos) { // single if (detPos >= 0) { - // position exceeds multi list size - if (detPos > detectors.size()) { - FILE_LOG(logERROR) << "Position " << detPos << " exceeds list of " << detectors.size(); - setErrorMask(getErrorMask() | MULTI_POS_EXCEEDS_LIST); + if(isDetectorIndexOutOfBounds()) return -1; - } int ret = detectors[detPos]->checkVersionCompatibility(t); if (detectors[detPos]->getErrorMask()) @@ -478,12 +467,8 @@ int64_t multiSlsDetector::getId(idMode mode, int detPos) { // single if (detPos >= 0) { - // position exceeds multi list size - if (detPos > detectors.size()) { - FILE_LOG(logERROR) << "Position " << detPos << " exceeds list of " << detectors.size(); - setErrorMask(getErrorMask() | MULTI_POS_EXCEEDS_LIST); + if(isDetectorIndexOutOfBounds()) return -1; - } int64_t ret = detectors[detPos]->getId(mode); if (detectors[detPos]->getErrorMask()) @@ -4614,3 +4599,13 @@ int multiSlsDetector::kbhit() { select(STDIN_FILENO+1, &fds, NULL, NULL, &tv); return FD_ISSET(STDIN_FILENO, &fds); } + +bool multiSlsDetector::isDetectorIndexOutOfBounds(int detPos) { + // position exceeds multi list size + if (detPos >= detectors.size()) { + FILE_LOG(logERROR) << "Position " << detPos << " is out of bounds with a detector list of " << detectors.size(); + setErrorMask(getErrorMask() | MULTI_POS_EXCEEDS_LIST); + return true; + } + return false; +} diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 2f4d454a4..e9e085551 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1569,6 +1569,11 @@ public: */ int setThreadedProcessing(int enable=-1); + /** + * Returns true if detector position is out of bounds + */ + bool isDetectorIndexOutOfBounds(int detPos); + private: /** * Initialize (open/create) shared memory for the sharedMultiDetector structure