diff --git a/CMakeLists.txt b/CMakeLists.txt index a058aa329..52fdb0056 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,10 +49,13 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) message(FATAL_ERROR "GCC version must be at least 4.8!") endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-misleading-indentation") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-misleading-indentation -Wno-stringop-truncation -Wno-class-memaccess") endif() - +# Suppressed warnings in GCC +# -Wno-stringop-truncation happens when we do sls::strcpy_safe truncates string instead of overwrite buffer +# -Wno-class-memaccess - on memcpy in rapidjson should be investigated upgrade implementation? +# -Wno-misleading-indentation - until clang format #set (CMAKE_CXX_STANDARD 11) #set (CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt index f33dbb231..aaf0d2bf9 100644 --- a/slsDetectorSoftware/CMakeLists.txt +++ b/slsDetectorSoftware/CMakeLists.txt @@ -23,7 +23,6 @@ target_include_directories(slsDetectorShared PUBLIC target_link_libraries(slsDetectorShared PUBLIC slsSupportLib ${ZeroMQ_LIBRARIES} - zmq ) set(PUBLICHEADERS diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index bb3064a73..934ff5ac1 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -512,7 +512,6 @@ void multiSlsDetector::addSlsDetector(const std::string &hostname) { detectors[pos]->setHostname(hostname); detectors[pos]->setOnline(true); - } slsDetectorDefs::detectorType multiSlsDetector::getDetectorTypeAsEnum(int detPos) { @@ -1934,7 +1933,7 @@ std::string multiSlsDetector::getAdditionalJsonHeader(int detPos) { return sls::concatenateIfDifferent(r); } -std::string multiSlsDetector::setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos) { +std::string multiSlsDetector::setAdditionalJsonParameter(const std::string &key, const std::string &value, int detPos) { // single if (detPos >= 0) { return detectors[detPos]->setAdditionalJsonParameter(key, value); @@ -1945,7 +1944,7 @@ std::string multiSlsDetector::setAdditionalJsonParameter(const std::string& key, return sls::concatenateIfDifferent(r); } -std::string multiSlsDetector::getAdditionalJsonParameter(const std::string& key, int detPos) { +std::string multiSlsDetector::getAdditionalJsonParameter(const std::string &key, int detPos) { // single if (detPos >= 0) { return detectors[detPos]->getAdditionalJsonParameter(key); @@ -2116,8 +2115,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) { } // multi - int xmin, xmax, ymin, ymax, channelX, channelY, idet, lastChannelX, - lastChannelY, index, offsetX, offsetY; + int xmin = 0, xmax = 0, ymin = 0, ymax = 0, channelX = 0, channelY = 0, idet = 0, lastChannelX = 0, + lastChannelY = 0, index = 0, offsetX = 0, offsetY = 0; bool invalidroi = false; int ndet = detectors.size(); @@ -2149,7 +2148,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) { // check roi max values idet = decodeNChannel(xmax, ymax, channelX, channelY); FILE_LOG(logDEBUG1) << "Decoded Channel max vals: " << std::endl - << "det:" << idet << "\t" << xmax << "\t" << ymax << "\t" << channelX << "\t" << channelY; + << "det:" << idet << "\t" << xmax << "\t" << ymax << "\t" << channelX << "\t" << channelY; if (idet == -1) { FILE_LOG(logERROR) << "invalid roi"; continue; @@ -2164,7 +2163,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) { // get offset for each detector idet = decodeNChannel(xmin, ymin, channelX, channelY); FILE_LOG(logDEBUG1) << "Decoded Channel min vals: " << std::endl - << "det:" << idet << "\t" << xmin << "\t" << ymin << "\t" << channelX << "\t" << channelY; + << "det:" << idet << "\t" << xmin << "\t" << ymin << "\t" << channelX << "\t" << channelY; if (idet < 0 || idet >= (int)detectors.size()) { FILE_LOG(logDEBUG1) << "invalid roi"; invalidroi = true; @@ -2172,13 +2171,13 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) { } // get last channel for each det in x and y dir lastChannelX = - (detectors[idet]->getTotalNumberOfChannelsInclGapPixels( - X)) - - 1; + (detectors[idet]->getTotalNumberOfChannelsInclGapPixels( + X)) - + 1; lastChannelY = - (detectors[idet]->getTotalNumberOfChannelsInclGapPixels( - Y)) - - 1; + (detectors[idet]->getTotalNumberOfChannelsInclGapPixels( + Y)) - + 1; offsetX = detectors[idet]->getDetectorOffset(X); offsetY = detectors[idet]->getDetectorOffset(Y); @@ -2192,7 +2191,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) { } FILE_LOG(logDEBUG1) << "lastChannelX:" << lastChannelX << "\t" - << "lastChannelY:" << lastChannelY; + << "lastChannelY:" << lastChannelY; // creating the list of roi for corresponding detector index = nroi[idet]; @@ -2218,16 +2217,15 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) { xmin = xmax + 1; } } - } else {// FIXME: check if xmax is greater? or reduce logic above? - idet=0; - nroi[idet]=n; - index = 0; + } else { // FIXME: check if xmax is greater? or reduce logic above? + idet = 0; + nroi[idet] = n; + index = 0; allroi[idet][index].xmin = xmin; allroi[idet][index].xmax = xmax; allroi[idet][index].ymin = ymin; allroi[idet][index].ymax = ymax; // nroi[idet] = nroi[idet] + 1; - } } diff --git a/slsSupportLib/include/ZmqSocket.h b/slsSupportLib/include/ZmqSocket.h index e58419a1e..9b422f2aa 100644 --- a/slsSupportLib/include/ZmqSocket.h +++ b/slsSupportLib/include/ZmqSocket.h @@ -254,7 +254,7 @@ public: char* additionalJsonHeader = 0) { - char buf[MAX_STR_LENGTH] = ""; + /** Json Header Format */ const char* jsonHeaderFormat = "{" @@ -286,7 +286,8 @@ public: "\"flippedDataX\":%u" ;//"}\n"; - int length = sprintf(buf, jsonHeaderFormat, + char buf[MAX_STR_LENGTH] = ""; + sprintf(buf, jsonHeaderFormat, jsonversion, dynamicrange, fileIndex, npixelsx, npixelsy, imageSize, acqIndex, fIndex, (fname == NULL)? "":fname, dummy?0:1, @@ -297,11 +298,13 @@ public: //additional stuff ((flippedData == 0 ) ? 0 :flippedData[0]) ); + if (additionalJsonHeader && strlen(additionalJsonHeader)) { - length = sprintf(buf, "%s, %s}\n", buf, additionalJsonHeader); - } else { - length = sprintf(buf, "%s}\n", buf); - } + strcat(buf, ", "); + strcat(buf, additionalJsonHeader); + } + strcat(buf, "}\n"); + int length = strlen(buf); #ifdef VERBOSE //if(!index) diff --git a/slsSupportLib/include/string_utils.h b/slsSupportLib/include/string_utils.h index f01af0fd9..cfd50cc1f 100644 --- a/slsSupportLib/include/string_utils.h +++ b/slsSupportLib/include/string_utils.h @@ -14,7 +14,7 @@ Still this is better than strcpy and a buffer overflow... */ template void strcpy_safe(char (&destination)[array_size], const char *source) { - strncpy(destination, source, array_size); + strncpy(destination, source, array_size-1); destination[array_size - 1] = '\0'; }