Mercurial > hg > orthanc
changeset 6747:6e2c28b976b4
clang-tidy (cont)
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp Fri May 08 13:50:16 2026 +0200 @@ -34,6 +34,7 @@ #include <iostream> +#include <limits> namespace Orthanc { @@ -694,11 +695,16 @@ // Sanity check if we face an unsupported DICOM file: Make // sure that we can read DICOM_TAG_PIXEL_DATA at the reported // position in the stream - stream.seekg(visitor.GetPixelDataOffset(), stream.beg); + if (visitor.GetPixelDataOffset() > static_cast<uint64_t>(std::numeric_limits<off_t>::max())) + { + throw OrthancException(ErrorCode_BadFileFormat, "PixelDataOffset too large"); + } + + stream.seekg(static_cast<off_t>(visitor.GetPixelDataOffset()), stream.beg); std::string s; s.resize(4); - stream.read(&s[0], s.size()); + stream.read(&s[0], static_cast<std::streamsize>(s.size())); if (!isLittleEndian) {
--- a/OrthancFramework/Sources/DicomNetworking/DicomAssociation.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancFramework/Sources/DicomNetworking/DicomAssociation.cpp Fri May 08 13:50:16 2026 +0200 @@ -233,7 +233,7 @@ } // Timeout used during association negociation and ASC_releaseAssociation() - uint32_t acseTimeout = parameters.GetTimeout(); + Sint32 acseTimeout = static_cast<Sint32>(parameters.GetTimeout()); if (acseTimeout == 0) { /** @@ -357,7 +357,9 @@ assert(!transferSyntaxes.empty()); CheckConnecting(parameters, ASC_addPresentationContext( params_, presentationContextId, abstractSyntax, - &transferSyntaxes[0], transferSyntaxes.size(), GetDcmtkRole(proposed_[i].role_))); + &transferSyntaxes[0], + static_cast<int>(transferSyntaxes.size()), + GetDcmtkRole(proposed_[i].role_))); presentationContextId += 2; } @@ -797,7 +799,7 @@ if (!DIMSE_receiveCommand(&association.GetDcmtkAssociation(), (parameters.HasTimeout() ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), - parameters.GetTimeout(), &presID, &message, + static_cast<Sint32>(parameters.GetTimeout()), &presID, &message, NULL /* no statusDetail */).good() || message.CommandField != DIMSE_N_EVENT_REPORT_RSP) { @@ -960,7 +962,7 @@ if (!DIMSE_receiveCommand(&association.GetDcmtkAssociation(), (parameters.HasTimeout() ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), - parameters.GetTimeout(), &presID, &message, + static_cast<Sint32>(parameters.GetTimeout()), &presID, &message, NULL /* no statusDetail */).good() || message.CommandField != DIMSE_N_ACTION_RSP) {
--- a/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.cpp Fri May 08 13:50:16 2026 +0200 @@ -89,7 +89,7 @@ chunk_.resize(CHUNK_SIZE); } - file_.read(&chunk_[0], chunk_.size()); + file_.read(&chunk_[0], static_cast<std::streamsize>(chunk_.size())); if ((file_.flags() & std::istream::failbit) || file_.gcount() < 0)
--- a/OrthancFramework/Sources/Images/ImageAccessor.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancFramework/Sources/Images/ImageAccessor.cpp Fri May 08 13:50:16 2026 +0200 @@ -229,11 +229,11 @@ width_ = width; height_ = height; pitch_ = pitch; - buffer_ = reinterpret_cast<uint8_t*>(const_cast<void*>(buffer)); + buffer_ = reinterpret_cast<uint8_t*>(const_cast<void*>(buffer)); // NOLINT(bugprone-casting-through-void) const uint64_t size = static_cast<uint64_t>(height) * static_cast<uint64_t>(pitch); - if (static_cast<uint64_t>(GetBytesPerPixel() * width) > static_cast<uint64_t>(pitch) || + if (static_cast<uint64_t>(GetBytesPerPixel()) * width > static_cast<uint64_t>(pitch) || static_cast<uint64_t>(static_cast<size_t>(size)) != size) { throw OrthancException(ErrorCode_ParameterOutOfRange, "Buffer larger than 4GB, which is too large for Orthanc running in 32bits"); @@ -261,7 +261,7 @@ const uint64_t size = static_cast<uint64_t>(height) * static_cast<uint64_t>(pitch); - if (static_cast<uint64_t>(GetBytesPerPixel() * width) > static_cast<uint64_t>(pitch) || + if (static_cast<uint64_t>(GetBytesPerPixel()) * width > static_cast<uint64_t>(pitch) || static_cast<uint64_t>(static_cast<size_t>(size)) != size) { throw OrthancException(ErrorCode_ParameterOutOfRange, "Buffer larger than 4GB, which is too large for Orthanc running in 32bits");
--- a/OrthancFramework/Sources/RestApi/RestApi.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancFramework/Sources/RestApi/RestApi.cpp Fri May 08 13:50:16 2026 +0200 @@ -597,7 +597,7 @@ else if (isupper(tag[i]) && tag[i - 1] == ' ') { - s.push_back(tolower(tag[i])); + s.push_back(static_cast<char>(tolower(tag[i]))); } else {
--- a/OrthancFramework/Sources/Toolbox.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancFramework/Sources/Toolbox.cpp Fri May 08 13:50:16 2026 +0200 @@ -704,7 +704,10 @@ size_t size) { MD5Context context; - context.Append(data, size); + if (data != NULL && size > 0) + { + context.Append(data, size); + } context.Export(result); } @@ -1927,7 +1930,7 @@ // http://userguide.icu-project.org/icudata#TOC-Alignment { - static const size_t ALIGN = 16; + static const intptr_t ALIGN = 16; UErrorCode status = U_ZERO_ERROR;
--- a/OrthancFramework/UnitTestsSources/ZipTests.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancFramework/UnitTestsSources/ZipTests.cpp Fri May 08 13:50:16 2026 +0200 @@ -239,7 +239,7 @@ large.resize(4 * 65536); for (size_t i = 0; i < large.size(); i++) { - large[i] = rand() % 256; + large[i] = static_cast<char>(rand() % 256); } for (int i = 0; i < 2; i++)
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Fri May 08 13:50:16 2026 +0200 @@ -667,7 +667,7 @@ FileContentType type) ORTHANC_OVERRIDE { OrthancPluginErrorCode error = create_ - (uuid.c_str(), content, size, Plugins::Convert(type)); + (uuid.c_str(), content, static_cast<int64_t>(size), Plugins::Convert(type)); if (error != OrthancPluginErrorCode_Success) { @@ -3830,7 +3830,7 @@ return; case _OrthancPluginService_GetInstanceSize: - *p.resultInt64 = instance.GetBufferSize(); + *p.resultInt64 = static_cast<int64_t>(instance.GetBufferSize()); return; case _OrthancPluginService_GetInstanceData:
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Fri May 08 13:50:16 2026 +0200 @@ -264,7 +264,7 @@ } else { - if (size > 0) + if (buffer != NULL && size > 0) { memcpy(buffer_.data, buffer, size); }
--- a/OrthancServer/Resources/orthanc.clang-tidy Fri May 08 13:04:56 2026 +0200 +++ b/OrthancServer/Resources/orthanc.clang-tidy Fri May 08 13:50:16 2026 +0200 @@ -1,5 +1,9 @@ +# Note, you must first run cmake with this option: -DCMAKE_EXPORT_COMPILE_COMMANDS=ON # ~/o/orthanc$ clear && find . -name "*.cpp" -print | xargs run-clang-tidy -p ../build/orthanc -config-file=/home/alain/o/orthanc/OrthancServer/Resources/orthanc.clang-tidy -# TODO: reactivate bugprone-implicit-widening-of-multiplication-result +# TODO: reactivate: +# bugprone-implicit-widening-of-multiplication-result +# bugprone-exception-escape + Checks: > -*, clang-analyzer-*, @@ -9,6 +13,7 @@ -bugprone-branch-clone, -bugprone-suspicious-include, -bugprone-implicit-widening-of-multiplication-result, + -bugprone-exception-escape, -performance-*, -readability-*, -modernize-*
--- a/OrthancServer/Sources/OrthancGetRequestHandler.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancServer/Sources/OrthancGetRequestHandler.cpp Fri May 08 13:50:16 2026 +0200 @@ -318,7 +318,7 @@ cond = DIMSE_storeUser( assoc, presId, &req, NULL /* imageFileName */, dicom->getDataset(), ProgressCallback, NULL /* callbackData */, - (timeout_ > 0 ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), timeout_, + (timeout_ > 0 ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), static_cast<int>(timeout_), &rsp, &stDetailTmp, &cancelParameters); stDetail.reset(stDetailTmp); } @@ -339,7 +339,7 @@ assoc, presId, &req, NULL /* imageFileName */, transcoded.GetParsed().getDataset(), ProgressCallback, NULL /* callbackData */, - (timeout_ > 0 ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), timeout_, + (timeout_ > 0 ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), static_cast<int>(timeout_), &rsp, &stDetailTmp, &cancelParameters); stDetail.reset(stDetailTmp); }
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp Fri May 08 13:50:16 2026 +0200 @@ -352,7 +352,7 @@ } - unsigned int OrthancRestApi::GetJobRequestPriority(const Json::Value& body) + int OrthancRestApi::GetJobRequestPriority(const Json::Value& body) { if (body.type() != Json::objectValue || !body.isMember(KEY_PRIORITY))
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.h Fri May 08 13:04:56 2026 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.h Fri May 08 13:50:16 2026 +0200 @@ -114,7 +114,7 @@ static bool IsSynchronousJobRequest(bool isDefaultSynchronous, const Json::Value& body); - static unsigned int GetJobRequestPriority(const Json::Value& body); + static int GetJobRequestPriority(const Json::Value& body); static void SubmitGenericJob(RestApiOutput& output, ServerContext& context,
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestArchive.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestArchive.cpp Fri May 08 13:50:16 2026 +0200 @@ -430,7 +430,12 @@ { try { - file_.write(chunk.c_str(), chunk.size()); + if (chunk.size() > std::numeric_limits<std::streamsize>::max()) + { + throw OrthancException(ErrorCode_InternalError, "Chunk too large"); + } + + file_.write(chunk.c_str(), static_cast<std::streamsize>(chunk.size())); if (!file_.good()) {
--- a/OrthancServer/Sources/ServerContext.cpp Fri May 08 13:04:56 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Fri May 08 13:50:16 2026 +0200 @@ -361,11 +361,12 @@ { metricsRegistry_->SetFloatValue("orthanc_dicom_cache_size_mb", static_cast<float>(dicomCache_.GetCurrentSize()) / static_cast<float>(1024 * 1024)); - metricsRegistry_->SetIntegerValue("orthanc_dicom_cache_count", dicomCache_.GetNumberOfItems()); - + metricsRegistry_->SetIntegerValue("orthanc_dicom_cache_count", + static_cast<int64_t>(dicomCache_.GetNumberOfItems())); metricsRegistry_->SetFloatValue("orthanc_storage_cache_size_mb", static_cast<float>(storageCache_.GetCurrentSize()) / static_cast<float>(1024 * 1024)); - metricsRegistry_->SetIntegerValue("orthanc_storage_cache_count", storageCache_.GetNumberOfItems()); + metricsRegistry_->SetIntegerValue("orthanc_storage_cache_count", + static_cast<int64_t>(storageCache_.GetNumberOfItems())); }
