Mercurial > hg > orthanc
changeset 6745:e0454c1f0a1b
clang-tidy (1)
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Fri, 08 May 2026 12:21:41 +0200 |
| parents | 827f3c162824 |
| children | 999f1b613bf0 |
| files | OrthancFramework/Sources/DicomFormat/StreamBlockReader.cpp OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp OrthancFramework/Sources/FileStorage/StorageAccessor.cpp OrthancFramework/Sources/Images/NumpyWriter.cpp OrthancFramework/Sources/Images/PamWriter.cpp OrthancFramework/Sources/RestApi/RestApiPath.cpp OrthancFramework/UnitTestsSources/ImageTests.cpp OrthancFramework/UnitTestsSources/ToolboxTests.cpp OrthancServer/Resources/orthanc.clang-tidy OrthancServer/Sources/ServerJobs/ArchiveJob.cpp OrthancServer/UnitTestsSources/ServerConfigTests.cpp |
| diffstat | 11 files changed, 69 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/StreamBlockReader.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancFramework/Sources/DicomFormat/StreamBlockReader.cpp Fri May 08 12:21:41 2026 +0200 @@ -26,6 +26,7 @@ #include "StreamBlockReader.h" #include "../OrthancException.h" +#include <limits> namespace Orthanc @@ -74,8 +75,8 @@ * "DicomStreamReader::LookupPixelDataOffset()" for buffers) **/ - size_t remainingBytes = block_.size() - blockPos_; - stream_.read(&block_[blockPos_], remainingBytes); + size_t remainingBytes = std::max(block_.size() - blockPos_, static_cast<size_t>(std::numeric_limits<std::streamsize>::max())); // avoid overflowing std::streamsize + stream_.read(&block_[blockPos_], static_cast<std::streamsize>(remainingBytes)); std::streamsize r = stream_.gcount(); if (r == 0)
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp Fri May 08 12:21:41 2026 +0200 @@ -148,7 +148,7 @@ !e->isaString() || !e->getString(c).good() || c == NULL || - strcmp("PMSCT_RLE1", c)) + strcmp("PMSCT_RLE1", c) != 0) { return false; } @@ -240,8 +240,8 @@ value = delta + (int8_t) temp[i]; } - output.push_back(value & 0xff); - output.push_back(value >> 8); + output.push_back(static_cast<char>(value & 0xff)); + output.push_back(static_cast<char>(value >> 8)); delta = value; }
--- a/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp Fri May 08 12:21:41 2026 +0200 @@ -354,7 +354,7 @@ if (metrics_ != NULL) { - metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, size); + metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, static_cast<int64_t>(size)); } if (cache_ != NULL) @@ -397,7 +397,7 @@ if (metrics_ != NULL) { - metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, compressed.size()); + metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, static_cast<int64_t>(compressed.size())); } if (cache_ != NULL) @@ -463,7 +463,7 @@ if (metrics_ != NULL) { - metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize()); + metrics_->IncrementIntegerValue(METRICS_READ_BYTES, static_cast<int64_t>(buffer->GetSize())); } buffer->MoveToString(content); @@ -484,7 +484,7 @@ if (metrics_ != NULL) { - metrics_->IncrementIntegerValue(METRICS_READ_BYTES, compressed->GetSize()); + metrics_->IncrementIntegerValue(METRICS_READ_BYTES, static_cast<int64_t>(compressed->GetSize())); } zlib.Uncompress(content, compressed->GetData(), compressed->GetSize()); @@ -543,7 +543,7 @@ if (metrics_ != NULL) { - metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize()); + metrics_->IncrementIntegerValue(METRICS_READ_BYTES, static_cast<int64_t>(buffer->GetSize())); } buffer->MoveToString(content); @@ -635,7 +635,7 @@ if (metrics_ != NULL) { - metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize()); + metrics_->IncrementIntegerValue(METRICS_READ_BYTES, static_cast<int64_t>(buffer->GetSize())); } buffer->MoveToString(target);
--- a/OrthancFramework/Sources/Images/NumpyWriter.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancFramework/Sources/Images/NumpyWriter.cpp Fri May 08 12:21:41 2026 +0200 @@ -140,7 +140,7 @@ void NumpyWriter::WritePixels(ChunkedBuffer& target, const ImageAccessor& image) { - size_t rowSize = image.GetBytesPerPixel() * image.GetWidth(); + size_t rowSize = static_cast<size_t>(image.GetBytesPerPixel()) * image.GetWidth(); for (unsigned int y = 0; y < image.GetHeight(); y++) {
--- a/OrthancFramework/Sources/Images/PamWriter.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancFramework/Sources/Images/PamWriter.cpp Fri May 08 12:21:41 2026 +0200 @@ -103,7 +103,7 @@ throw OrthancException(ErrorCode_NotImplemented); } - size_t targetPitch = channelCount * bytesPerChannel * width; + size_t targetPitch = static_cast<size_t>(channelCount) * bytesPerChannel * width; size_t offset = target.size(); target.resize(offset + targetPitch * height); @@ -117,9 +117,9 @@ for (unsigned int h = 0; h < height; ++h) { const uint16_t* p = reinterpret_cast<const uint16_t*> - (reinterpret_cast<const uint8_t*>(buffer) + h * sourcePitch); + (reinterpret_cast<const uint8_t*>(buffer) + static_cast<size_t>(h) * sourcePitch); uint16_t* q = reinterpret_cast<uint16_t*> - (reinterpret_cast<uint8_t*>(&target[offset]) + h * targetPitch); + (reinterpret_cast<uint8_t*>(&target[offset]) + static_cast<size_t>(h) * targetPitch); for (unsigned int w = 0; w < width * channelCount; ++w) { @@ -152,8 +152,8 @@ for (unsigned int h = 0; h < height; ++h) { - const void* p = reinterpret_cast<const uint8_t*>(buffer) + h * sourcePitch; - void* q = reinterpret_cast<uint8_t*>(&target[offset]) + h * targetPitch; + const void* p = reinterpret_cast<const uint8_t*>(buffer) + static_cast<size_t>(h) * sourcePitch; + void* q = reinterpret_cast<uint8_t*>(&target[offset]) + static_cast<size_t>(h) * targetPitch; memcpy(q, p, targetPitch); } }
--- a/OrthancFramework/Sources/RestApi/RestApiPath.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancFramework/Sources/RestApi/RestApiPath.cpp Fri May 08 12:21:41 2026 +0200 @@ -118,7 +118,7 @@ if (hasTrailing_) { - trailing.assign(uri.begin() + uri_.size(), uri.end()); + trailing.assign(uri.begin() + static_cast<UriComponents::difference_type>(uri_.size()), uri.end()); } return true;
--- a/OrthancFramework/UnitTestsSources/ImageTests.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancFramework/UnitTestsSources/ImageTests.cpp Fri May 08 12:21:41 2026 +0200 @@ -56,10 +56,10 @@ unsigned int height = 61; unsigned int pitch = width * 3; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); for (unsigned int y = 0; y < height; y++) { - uint8_t *p = &image[0] + y * pitch; + uint8_t *p = &image[0] + static_cast<size_t>(y) * pitch; for (unsigned int x = 0; x < width; x++, p += 3) { p[0] = (y % 3 == 0) ? 255 : 0; @@ -92,10 +92,10 @@ unsigned int height = 61; unsigned int pitch = width * 8; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); for (unsigned int y = 0; y < height; y++) { - uint8_t *p = &image[0] + y * pitch; + uint8_t *p = &image[0] + static_cast<size_t>(y) * pitch; for (unsigned int x = 0; x < width; x++, p += 8) { switch (Orthanc::Toolbox::DetectEndianness()) @@ -153,10 +153,10 @@ int height = 256; int pitch = width; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); for (int y = 0; y < height; y++) { - uint8_t *p = &image[0] + y * pitch; + uint8_t *p = &image[0] + static_cast<size_t>(y) * pitch; for (int x = 0; x < width; x++, p++) { *p = y; @@ -187,12 +187,12 @@ int height = 256; int pitch = width * 2 + 16; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); int v = 0; for (int y = 0; y < height; y++) { - uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); + uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + static_cast<size_t>(y) * pitch); for (int x = 0; x < width; x++, p++, v++) { *p = v; @@ -223,12 +223,12 @@ unsigned int height = 256; unsigned int pitch = width * 2 + 16; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); int v = 0; for (unsigned int y = 0; y < height; y++) { - uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); + uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + static_cast<size_t>(y) * pitch); for (unsigned int x = 0; x < width; x++, p++, v++) { *p = v; @@ -252,7 +252,7 @@ v = 0; for (unsigned int y = 0; y < height; y++) { - const uint16_t *p = reinterpret_cast<const uint16_t*>(reinterpret_cast<const uint8_t*>(r.GetConstBuffer()) + y * r.GetPitch()); + const uint16_t *p = reinterpret_cast<const uint16_t*>(reinterpret_cast<const uint8_t*>(r.GetConstBuffer()) + static_cast<size_t>(y) * r.GetPitch()); ASSERT_EQ(p, r.GetConstRow(y)); for (unsigned int x = 0; x < width; x++, p++, v++) { @@ -276,7 +276,7 @@ v = 0; for (unsigned int y = 0; y < height; y++) { - const uint16_t *p = reinterpret_cast<const uint16_t*>(reinterpret_cast<const uint8_t*>(r2.GetConstBuffer()) + y * r2.GetPitch()); + const uint16_t *p = reinterpret_cast<const uint16_t*>(reinterpret_cast<const uint8_t*>(r2.GetConstBuffer()) + static_cast<size_t>(y) * r2.GetPitch()); ASSERT_EQ(p, r2.GetConstRow(y)); for (unsigned int x = 0; x < width; x++, p++, v++) { @@ -364,10 +364,10 @@ unsigned int height = 61; unsigned int pitch = width * 3; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); for (unsigned int y = 0; y < height; y++) { - uint8_t *p = &image[0] + y * pitch; + uint8_t *p = &image[0] + static_cast<size_t>(y) * pitch; for (unsigned int x = 0; x < width; x++, p += 3) { p[0] = (y % 3 == 0) ? 255 : 0; @@ -400,10 +400,10 @@ int height = 256; int pitch = width; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); for (int y = 0; y < height; y++) { - uint8_t *p = &image[0] + y * pitch; + uint8_t *p = &image[0] + static_cast<size_t>(y) * pitch; for (int x = 0; x < width; x++, p++) { *p = y; @@ -434,12 +434,12 @@ int height = 256; int pitch = width * 2 + 16; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); int v = 0; for (int y = 0; y < height; y++) { - uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); + uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + static_cast<size_t>(y) * pitch); for (int x = 0; x < width; x++, p++, v++) { *p = v; @@ -470,12 +470,12 @@ unsigned int height = 256; unsigned int pitch = width * 2 + 16; - std::vector<uint8_t> image(height * pitch); + std::vector<uint8_t> image(static_cast<size_t>(height) * pitch); int v = 0; for (unsigned int y = 0; y < height; y++) { - uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); + uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + static_cast<size_t>(y) * pitch); for (unsigned int x = 0; x < width; x++, p++, v++) { *p = v; @@ -500,7 +500,7 @@ for (unsigned int y = 0; y < height; y++) { const uint16_t *p = reinterpret_cast<const uint16_t*> - (reinterpret_cast<const uint8_t*>(r.GetConstBuffer()) + y * r.GetPitch()); + (reinterpret_cast<const uint8_t*>(r.GetConstBuffer()) + static_cast<size_t>(y) * r.GetPitch()); ASSERT_EQ(p, r.GetConstRow(y)); for (unsigned int x = 0; x < width; x++, p++, v++) { @@ -522,7 +522,7 @@ for (unsigned int y = 0; y < height; y++) { const uint16_t* p = reinterpret_cast<const uint16_t*> - (reinterpret_cast<const uint8_t*>(r.GetConstBuffer()) + y * r.GetPitch()); + (reinterpret_cast<const uint8_t*>(r.GetConstBuffer()) + static_cast<size_t>(y) * r.GetPitch()); ASSERT_EQ(p, r.GetConstRow(y)); for (unsigned int x = 0; x < width; x++, p++, v++) { @@ -547,7 +547,7 @@ for (unsigned int y = 0; y < height; y++) { const uint16_t *p = reinterpret_cast<const uint16_t*> - (reinterpret_cast<const uint8_t*>(r2.GetConstBuffer()) + y * r2.GetPitch()); + (reinterpret_cast<const uint8_t*>(r2.GetConstBuffer()) + static_cast<size_t>(y) * r2.GetPitch()); ASSERT_EQ(p, r2.GetConstRow(y)); for (unsigned int x = 0; x < width; x++, p++, v++) { @@ -574,7 +574,7 @@ for (unsigned int y = 0; y < height; y++) { const uint16_t* p = reinterpret_cast<const uint16_t*> - (reinterpret_cast<const uint8_t*>(r2.GetConstBuffer()) + y * r2.GetPitch()); + (reinterpret_cast<const uint8_t*>(r2.GetConstBuffer()) + static_cast<size_t>(y) * r2.GetPitch()); ASSERT_EQ(p, r2.GetConstRow(y)); for (unsigned int x = 0; x < width; x++, p++, v++) { @@ -591,8 +591,8 @@ Orthanc::Image image16(Orthanc::PixelFormat_Grayscale16, 32, 32, false); Orthanc::Image image8(Orthanc::PixelFormat_Grayscale8, 32, 32, false); - memset(image16.GetBuffer(), 0, image16.GetHeight() * image16.GetPitch()); - memset(image8.GetBuffer(), 0, image8.GetHeight() * image8.GetPitch()); + memset(image16.GetBuffer(), 0, static_cast<size_t>(image16.GetHeight()) * image16.GetPitch()); + memset(image8.GetBuffer(), 0, static_cast<size_t>(image8.GetHeight()) * image8.GetPitch()); { Orthanc::PamWriter w;
--- a/OrthancFramework/UnitTestsSources/ToolboxTests.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancFramework/UnitTestsSources/ToolboxTests.cpp Fri May 08 12:21:41 2026 +0200 @@ -87,10 +87,10 @@ std::string base64Result; std::string decodedResult; - size_t size = 2*256; + size_t size = static_cast<size_t>(2)*256; toEncode.reserve(size); for (size_t i = 0; i < size; i++) - toEncode.push_back(i % 256); + toEncode.push_back(static_cast<char>(i % 256)); Toolbox::EncodeBase64(base64Result, toEncode); Toolbox::DecodeBase64(decodedResult, base64Result); @@ -404,9 +404,9 @@ TEST(Toolbox, GetHumanTransferSpeed) { ASSERT_EQ("8.00Mbps", Toolbox::GetHumanTransferSpeed(false, 1000, 1000000)); - ASSERT_EQ("8.59Gbps", Toolbox::GetHumanTransferSpeed(false, 1024*1024*1024, 1000000000)); - ASSERT_EQ("1.00GB in 1.00s = 8.59Gbps", Toolbox::GetHumanTransferSpeed(true, 1024*1024*1024, 1000000000)); - ASSERT_EQ("976.56KB in 1.00s = 8.00Mbps", Toolbox::GetHumanTransferSpeed(true, 1000*1000, 1000000000)); + ASSERT_EQ("8.59Gbps", Toolbox::GetHumanTransferSpeed(false, 1024ull*1024*1024, 1000000000)); + ASSERT_EQ("1.00GB in 1.00s = 8.59Gbps", Toolbox::GetHumanTransferSpeed(true, 1024ull*1024*1024, 1000000000)); + ASSERT_EQ("976.56KB in 1.00s = 8.00Mbps", Toolbox::GetHumanTransferSpeed(true, 1000ull*1000, 1000000000)); } TEST(Toolbox, DISABLED_JapaneseBackslashes)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Resources/orthanc.clang-tidy Fri May 08 12:21:41 2026 +0200 @@ -0,0 +1,17 @@ +# ~/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 +Checks: > + -*, + clang-analyzer-*, + -clang-analyzer-optin.core.EnumCastOutOfRange, + bugprone-*, + -bugprone-easily-swappable-parameters, + -bugprone-branch-clone, + -bugprone-suspicious-include, + -bugprone-implicit-widening-of-multiplication-result, + -performance-*, + -readability-*, + -modernize-* + +HeaderFilterRegex: '^(OrthancServer|OrthancFramework)/' +SystemHeaders: false \ No newline at end of file
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Fri May 08 12:21:41 2026 +0200 @@ -45,8 +45,8 @@ #define snprintf _snprintf #endif -static const uint64_t MEGA_BYTES = 1024 * 1024; -static const uint64_t GIGA_BYTES = 1024 * 1024 * 1024; +static const uint64_t MEGA_BYTES = 1024ull * 1024; +static const uint64_t GIGA_BYTES = 1024ull * 1024 * 1024; static const char* const MEDIA_IMAGES_FOLDER = "IMAGES"; static const char* const KEY_DESCRIPTION = "Description";
--- a/OrthancServer/UnitTestsSources/ServerConfigTests.cpp Fri May 08 09:22:31 2026 +0200 +++ b/OrthancServer/UnitTestsSources/ServerConfigTests.cpp Fri May 08 12:21:41 2026 +0200 @@ -36,8 +36,6 @@ TEST(ServerConfig, AcceptedSopClasses) { - const std::string path = "UnitTestsStorage"; - PluginStorageAreaAdapter storage(new MemoryStorageArea); SQLiteDatabaseWrapper db; // The SQLite DB is in memory db.Open();
