# HG changeset patch # User Sebastien Jodogne # Date 1600323508 -7200 # Node ID 2d5209153b32fb6152d20b853511203554ffbbc9 # Parent 7112a8af0b632bacb7bb054d37f21bc6395a0d4a cppcheck diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp --- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -346,7 +346,7 @@ template - static void CopyPixels(const ImageAccessor& target, + static void CopyPixels(ImageAccessor& target, const DicomIntegerPixelAccessor& source) { // WARNING - "::min()" should be replaced by "::lowest()" if diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpClient.cpp --- a/OrthancFramework/Sources/HttpClient.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpClient.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -117,7 +117,7 @@ { } - CurlHeaders(const HttpClient::HttpHeaders& headers) + explicit CurlHeaders(const HttpClient::HttpHeaders& headers) { for (HttpClient::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it) @@ -318,7 +318,6 @@ try { assert(userdata != NULL); - CurlAnswer& that = *(static_cast(userdata)); size_t length = size * nmemb; if (length == 0) @@ -333,6 +332,7 @@ if (colon != std::string::npos && eol != std::string::npos) { + CurlAnswer& that = *(static_cast(userdata)); std::string tmp(s.substr(0, colon)); if (that.headersLowerCase_) @@ -345,6 +345,7 @@ if (!key.empty()) { std::string value = Toolbox::StripSpaces(s.substr(colon + 1, eol)); + that.answer_.AddHeader(key, value); } } @@ -369,7 +370,6 @@ try { assert(userdata != NULL); - CurlAnswer& that = *(static_cast(userdata)); size_t length = size * nmemb; if (length == 0) @@ -378,6 +378,7 @@ } else { + CurlAnswer& that = *(static_cast(userdata)); that.answer_.AddChunk(buffer, length); return length; } @@ -419,7 +420,7 @@ } virtual void AddHeader(const std::string& key, - const std::string& value) + const std::string& value) ORTHANC_OVERRIDE { if (headers_ != NULL) { @@ -428,7 +429,7 @@ } virtual void AddChunk(const void* data, - size_t size) + size_t size) ORTHANC_OVERRIDE { answer_.AddChunk(data, size); } diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h --- a/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h Thu Sep 17 08:18:28 2020 +0200 @@ -67,19 +67,19 @@ * Implementation of the IHttpStreamAnswer interface. **/ - virtual uint64_t GetContentLength() + virtual uint64_t GetContentLength() ORTHANC_OVERRIDE { return size_; } - virtual bool ReadNextChunk(); + virtual bool ReadNextChunk() ORTHANC_OVERRIDE; - virtual const char* GetChunkContent() + virtual const char* GetChunkContent() ORTHANC_OVERRIDE { return chunk_.c_str(); } - virtual size_t GetChunkSize() + virtual size_t GetChunkSize() ORTHANC_OVERRIDE { return chunkSize_; } diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpServer/HttpOutput.cpp --- a/OrthancFramework/Sources/HttpServer/HttpOutput.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpOutput.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -51,6 +51,7 @@ state_(State_WritingHeader), status_(HttpStatus_200_Ok), hasContentLength_(false), + contentLength_(0), contentPosition_(0), keepAlive_(isKeepAlive) { diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpServer/HttpServer.cpp --- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -83,7 +83,8 @@ struct mg_connection* connection_; public: - MongooseOutputStream(struct mg_connection* connection) : connection_(connection) + explicit MongooseOutputStream(struct mg_connection* connection) : + connection_(connection) { } @@ -146,7 +147,7 @@ std::string filename_; public: - ChunkedFile(const std::string& filename) : + explicit ChunkedFile(const std::string& filename) : filename_(filename) { } @@ -284,6 +285,11 @@ { struct mg_context *context_; ChunkStore chunkStore_; + + PImpl() : + context_(NULL) + { + } }; @@ -300,18 +306,19 @@ size_t length; try { - length = boost::lexical_cast(contentLength); + int64_t tmp = boost::lexical_cast(contentLength); + if (tmp < 0) + { + return PostDataStatus_NoLength; + } + + length = static_cast(tmp); } catch (boost::bad_lexical_cast&) { return PostDataStatus_NoLength; } - if (length < 0) - { - length = 0; - } - body.resize(length); size_t pos = 0; @@ -500,10 +507,7 @@ { // This file is stored in a single chunk completedFile.resize(chunkSize); - if (chunkSize > 0) - { - memcpy(&completedFile[0], chunkData, chunkSize); - } + memcpy(&completedFile[0], chunkData, chunkSize); return PostDataStatus_Success; } else @@ -1053,24 +1057,23 @@ } - HttpServer::HttpServer() : pimpl_(new PImpl) + HttpServer::HttpServer() : + pimpl_(new PImpl), + handler_(NULL), + remoteAllowed_(false), + authentication_(false), + sslVerifyPeers_(false), + ssl_(false), + port_(8000), + filter_(NULL), + keepAlive_(false), + httpCompression_(true), + exceptionFormatter_(NULL), + realm_(ORTHANC_REALM), + threadsCount_(50), // Default value in mongoose + tcpNoDelay_(true), + requestTimeout_(30) // Default value in mongoose/civetweb (30 seconds) { - pimpl_->context_ = NULL; - handler_ = NULL; - remoteAllowed_ = false; - authentication_ = false; - ssl_ = false; - sslVerifyPeers_ = false; - port_ = 8000; - filter_ = NULL; - keepAlive_ = false; - httpCompression_ = true; - exceptionFormatter_ = NULL; - realm_ = ORTHANC_REALM; - threadsCount_ = 50; // Default value in mongoose - tcpNoDelay_ = true; - requestTimeout_ = 30; // Default value in mongoose/civetweb (30 seconds) - #if ORTHANC_ENABLE_MONGOOSE == 1 LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server"; #endif @@ -1384,7 +1387,7 @@ void HttpServer::SetThreadsCount(unsigned int threads) { - if (threads <= 0) + if (threads == 0) { throw OrthancException(ErrorCode_ParameterOutOfRange); } @@ -1407,7 +1410,7 @@ void HttpServer::SetRequestTimeout(unsigned int seconds) { - if (seconds <= 0) + if (seconds == 0) { throw OrthancException(ErrorCode_ParameterOutOfRange, "Request timeout must be a stricly positive integer"); diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h --- a/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h Thu Sep 17 08:18:28 2020 +0200 @@ -60,24 +60,24 @@ // This is the first method to be called virtual HttpCompression SetupHttpCompression(bool gzipAllowed, - bool deflateAllowed); + bool deflateAllowed) ORTHANC_OVERRIDE; - virtual bool HasContentFilename(std::string& filename) + virtual bool HasContentFilename(std::string& filename) ORTHANC_OVERRIDE { return source_.HasContentFilename(filename); } - virtual std::string GetContentType() + virtual std::string GetContentType() ORTHANC_OVERRIDE { return source_.GetContentType(); } - virtual uint64_t GetContentLength(); + virtual uint64_t GetContentLength() ORTHANC_OVERRIDE; - virtual bool ReadNextChunk(); + virtual bool ReadNextChunk() ORTHANC_OVERRIDE; - virtual const char* GetChunkContent(); + virtual const char* GetChunkContent() ORTHANC_OVERRIDE; - virtual size_t GetChunkSize(); + virtual size_t GetChunkSize() ORTHANC_OVERRIDE; }; } diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpServer/MultipartStreamReader.h --- a/OrthancFramework/Sources/HttpServer/MultipartStreamReader.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/MultipartStreamReader.h Thu Sep 17 08:18:28 2020 +0200 @@ -64,7 +64,7 @@ void ParseStream(); public: - MultipartStreamReader(const std::string& boundary); + explicit MultipartStreamReader(const std::string& boundary); void SetBlockSize(size_t size); diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpServer/StringHttpOutput.h --- a/OrthancFramework/Sources/HttpServer/StringHttpOutput.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/StringHttpOutput.h Thu Sep 17 08:18:28 2020 +0200 @@ -39,11 +39,11 @@ { } - virtual void OnHttpStatusReceived(HttpStatus status); + virtual void OnHttpStatusReceived(HttpStatus status) ORTHANC_OVERRIDE; - virtual void Send(bool isHeader, const void* buffer, size_t length); + virtual void Send(bool isHeader, const void* buffer, size_t length) ORTHANC_OVERRIDE; - virtual void DisableKeepAlive() + virtual void DisableKeepAlive() ORTHANC_OVERRIDE { } diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpServer/StringMatcher.cpp --- a/OrthancFramework/Sources/HttpServer/StringMatcher.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/StringMatcher.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -42,7 +42,7 @@ public: // WARNING - The lifetime of "pattern_" must be larger than // "search_", as the latter internally keeps a pointer to "pattern" (*) - Search(const std::string& pattern) : + explicit Search(const std::string& pattern) : algorithm_(pattern.begin(), pattern.end()) { } diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/HttpServer/StringMatcher.h --- a/OrthancFramework/Sources/HttpServer/StringMatcher.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/StringMatcher.h Thu Sep 17 08:18:28 2020 +0200 @@ -46,7 +46,7 @@ Iterator matchEnd_; public: - StringMatcher(const std::string& pattern); + explicit StringMatcher(const std::string& pattern); const std::string& GetPattern() const { diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/Images/FontRegistry.cpp --- a/OrthancFramework/Sources/Images/FontRegistry.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/Images/FontRegistry.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -70,7 +70,7 @@ const Font* FontRegistry::FindFont(const std::string& fontName) const { - for (Fonts::const_iterator it = fonts_.begin(); it != fonts_.end(); it++) + for (Fonts::const_iterator it = fonts_.begin(); it != fonts_.end(); ++it) { if ((*it)->GetName() == fontName) { diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/Images/ImageAccessor.cpp --- a/OrthancFramework/Sources/Images/ImageAccessor.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/Images/ImageAccessor.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -92,7 +92,7 @@ } - void* ImageAccessor::GetBuffer() const + void* ImageAccessor::GetBuffer() { if (readOnly_) { @@ -117,7 +117,7 @@ } - void* ImageAccessor::GetRow(unsigned int y) const + void* ImageAccessor::GetRow(unsigned int y) { if (readOnly_) { diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/Images/ImageAccessor.h --- a/OrthancFramework/Sources/Images/ImageAccessor.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/Images/ImageAccessor.h Thu Sep 17 08:18:28 2020 +0200 @@ -110,11 +110,11 @@ return buffer_; } - void* GetBuffer() const; + void* GetBuffer(); const void* GetConstRow(unsigned int y) const; - void* GetRow(unsigned int y) const; + void* GetRow(unsigned int y); void AssignEmpty(PixelFormat format); diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/Images/ImageProcessing.cpp --- a/OrthancFramework/Sources/Images/ImageProcessing.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/Images/ImageProcessing.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -418,7 +418,7 @@ for (unsigned int y = 0; y < height; y++) { TargetType* p = reinterpret_cast(target.GetRow(y)); - const SourceType* q = reinterpret_cast(source.GetRow(y)); + const SourceType* q = reinterpret_cast(source.GetConstRow(y)); for (unsigned int x = 0; x < width; x++, p++, q++) { @@ -1860,15 +1860,15 @@ std::vector nodeX; nodeX.resize(cpSize); - int nodes, pixelX, pixelY, i, j, swap ; + int pixelX, pixelY, i, swap ; // Loop through the rows of the image. for (pixelY = top; pixelY < bottom; pixelY++) { double y = (double)pixelY; // Build a list of nodes. - nodes = 0; - j = static_cast(cpSize) - 1; + int nodes = 0; + int j = static_cast(cpSize) - 1; for (i = 0; i < static_cast(cpSize); i++) { @@ -2047,7 +2047,7 @@ void ImageProcessing::Resize(ImageAccessor& target, const ImageAccessor& source) { - if (source.GetFormat() != source.GetFormat()) + if (source.GetFormat() != target.GetFormat()) { throw OrthancException(ErrorCode_IncompatibleImageFormat); } diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/Images/PamReader.cpp --- a/OrthancFramework/Sources/Images/PamReader.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/Images/PamReader.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -180,7 +180,7 @@ unsigned int bytesPerChannel; PixelFormat format; - GetPixelFormat(format, bytesPerChannel, maxValue, channelCount, tupleType.c_str()); + GetPixelFormat(format, bytesPerChannel, maxValue, channelCount, tupleType); unsigned int pitch = width * channelCount * bytesPerChannel; diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/Images/PngReader.cpp --- a/OrthancFramework/Sources/Images/PngReader.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/Images/PngReader.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -42,7 +42,7 @@ { FILE* fp_; - FileRabi(const char* filename) + explicit FileRabi(const char* filename) { fp_ = SystemToolbox::OpenFile(filename, FileMode_ReadBinary); if (!fp_) @@ -81,12 +81,11 @@ } } - PngRabi() + PngRabi() : + png_(NULL), + info_(NULL), + endInfo_(NULL) { - png_ = NULL; - info_ = NULL; - endInfo_ = NULL; - png_ = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_) { diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/JobsEngine/Operations/JobOperationValue.h --- a/OrthancFramework/Sources/JobsEngine/Operations/JobOperationValue.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/JobsEngine/Operations/JobOperationValue.h Thu Sep 17 08:18:28 2020 +0200 @@ -43,7 +43,7 @@ Type type_; protected: - JobOperationValue(Type type) : + explicit JobOperationValue(Type type) : type_(type) { } diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h --- a/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h Thu Sep 17 08:18:28 2020 +0200 @@ -83,7 +83,7 @@ boost::mutex::scoped_lock lock_; public: - Lock(SequenceOfOperationsJob& that) : + explicit Lock(SequenceOfOperationsJob& that) : that_(that), lock_(that.mutex_) { diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/JobsEngine/Operations/StringOperationValue.h --- a/OrthancFramework/Sources/JobsEngine/Operations/StringOperationValue.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/JobsEngine/Operations/StringOperationValue.h Thu Sep 17 08:18:28 2020 +0200 @@ -34,7 +34,7 @@ std::string content_; public: - StringOperationValue(const std::string& content) : + explicit StringOperationValue(const std::string& content) : JobOperationValue(JobOperationValue::Type_String), content_(content) { diff -r 7112a8af0b63 -r 2d5209153b32 OrthancFramework/Sources/WebServiceParameters.h --- a/OrthancFramework/Sources/WebServiceParameters.h Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancFramework/Sources/WebServiceParameters.h Thu Sep 17 08:18:28 2020 +0200 @@ -58,7 +58,7 @@ public: WebServiceParameters(); - WebServiceParameters(const Json::Value& serialized) + explicit WebServiceParameters(const Json::Value& serialized) { Unserialize(serialized); } diff -r 7112a8af0b63 -r 2d5209153b32 OrthancServer/Plugins/Engine/OrthancPlugins.cpp --- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Wed Sep 16 20:53:31 2020 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Thu Sep 17 08:18:28 2020 +0200 @@ -3901,7 +3901,7 @@ case _OrthancPluginService_GetImageBuffer: { const _OrthancPluginGetImageInfo& p = *reinterpret_cast(parameters); - *(p.resultBuffer) = reinterpret_cast(p.image)->GetBuffer(); + *(p.resultBuffer) = const_cast(reinterpret_cast(p.image)->GetConstBuffer()); return true; }