Skip to content

Commit

Permalink
Fix additional clang-tidy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
azrogers committed Dec 17, 2024
1 parent 77094ed commit 7ef48d5
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 63 deletions.
40 changes: 20 additions & 20 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ Checks:
- "-*"
- "misc-include-cleaner"
- "bugprone-argument-comment"
#- "bugprone-assert-side-effect"
#- "bugprone-assignment-in-if-condition"
#- "bugprone-bad-signal-to-kill-thread"
#- "bugprone-bool-pointer-implicit-conversion"
#- "bugprone-branch-clone"
#- "bugprone-casting-through-void"
#- "bugprone-chained-comparison"
#- "bugprone-compare-pointer-to-member-virtual-function"
#- "bugprone-copy-constructor-init"
- "bugprone-assert-side-effect"
- "bugprone-assignment-in-if-condition"
- "bugprone-bad-signal-to-kill-thread"
- "bugprone-bool-pointer-implicit-conversion"
- "bugprone-branch-clone"
- "bugprone-casting-through-void"
- "bugprone-chained-comparison"
- "bugprone-compare-pointer-to-member-virtual-function"
- "bugprone-copy-constructor-init"
#- "bugprone-crtp-constructor-accessibility"
#- "bugprone-dangling-handle"
#- "bugprone-dynamic-static-initializers"
#- "-bugprone-easily-swappable-parameters"
#- "bugprone-empty-catch"
- "bugprone-dangling-handle"
- "bugprone-dynamic-static-initializers"
- "-bugprone-easily-swappable-parameters"
- "bugprone-empty-catch"
#- "bugprone-exception-escape"
#- "bugprone-fold-init-type"
#- "bugprone-forward-declaration-namespace"
#- "bugprone-forwarding-reference-overload"
#- "bugprone-implicit-widening-of-multiplication-result"
#- "bugprone-inaccurate-erase"
#- "bugprone-inc-dec-in-conditions"
#- "bugprone-incorrect-enable-if"
- "bugprone-fold-init-type"
- "bugprone-forward-declaration-namespace"
- "bugprone-forwarding-reference-overload"
- "bugprone-implicit-widening-of-multiplication-result"
- "bugprone-inaccurate-erase"
- "bugprone-inc-dec-in-conditions"
- "bugprone-incorrect-enable-if"
#- "bugprone-incorrect-roundings"
#- "bugprone-infinite-loop"
#- "bugprone-unhandled-self-assignment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGltf/Ktx2TranscodeTargets.h>

#include <cstddef>
#include <functional>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -204,7 +205,7 @@ struct CESIUM3DTILESSELECTION_API TilesetOptions {
* unloaded until the total is under this number or until only required tiles
* remain, whichever comes first.
*/
int64_t maximumCachedBytes = 512 * 1024 * 1024;
int64_t maximumCachedBytes = static_cast<int64_t>(512 * 1024 * 1024);

/**
* @brief A table that maps the camera height above the ellipsoid to a fog
Expand Down
6 changes: 4 additions & 2 deletions Cesium3DTilesSelection/src/EllipsoidTilesetLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ EllipsoidTilesetLoader::createGeometry(const Tile& tile) const {
static constexpr uint16_t resolution = 24;

std::vector<uint16_t> indices;
indices.reserve(6 * (resolution - 1) * (resolution - 1));
indices.reserve(
static_cast<size_type>(6 * (resolution - 1) * (resolution - 1)));

std::vector<glm::vec3> vertices(resolution * resolution);
std::vector<glm::vec3> vertices(
static_cast<size_type>(resolution * resolution));
std::vector<glm::vec3> normals(vertices.size());

const Ellipsoid& ellipsoid = _projection.getEllipsoid();
Expand Down
5 changes: 2 additions & 3 deletions Cesium3DTilesSelection/src/Tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,9 @@ Tileset::TraversalDetails Tileset::_visitTile(
// initially marked for RENDER here, it may later switch to REFINE as a
// result of `mustContinueRefiningToDeeperTiles`.
VisitTileAction action = VisitTileAction::Render;
if (unconditionallyRefine)
action = VisitTileAction::Refine;
else if (!meetsSse && !ancestorMeetsSse)
if (unconditionallyRefine || (!meetsSse && !ancestorMeetsSse)) {
action = VisitTileAction::Refine;
}

const TileSelectionState lastFrameSelectionState =
tile.getLastSelectionState();
Expand Down
4 changes: 2 additions & 2 deletions Cesium3DTilesSelection/test/TestTilesetContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ CesiumGltf::Model createGlobeGrid(
glm::dvec3 max = min;

std::vector<glm::dvec3> positions;
indices.reserve(6 * (width - 1) * (height - 1));
positions.reserve(width * height);
indices.reserve(static_cast<size_type>(6 * (width - 1) * (height - 1)));
positions.reserve(static_cast<size_type>(width * height));
for (uint32_t y = 0; y < height; ++y) {
for (uint32_t x = 0; x < width; ++x) {
double longitude = beginPoint.longitude + x * dimension;
Expand Down
2 changes: 1 addition & 1 deletion CesiumAsync/include/CesiumAsync/SharedAssetDepot.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CESIUMASYNC_API SharedAssetDepot
*
* Default is 16MiB.
*/
int64_t inactiveAssetSizeLimitBytes = 16 * 1024 * 1024;
int64_t inactiveAssetSizeLimitBytes = static_cast<int64_t>(16 * 1024 * 1024);

/**
* @brief Signature for the callback function that will be called to fetch and
Expand Down
8 changes: 5 additions & 3 deletions CesiumAsync/src/InternalTimegm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "InternalTimegm.h"

#include <cstddef>
#include <cstdint>
#include <ctime>

Expand Down Expand Up @@ -33,9 +34,10 @@ time_t internalTimegm(std::tm const* t) {
const int day_of_year = daysFrom1jan(year, month, day);
const int days_since_epoch = daysFrom1970(year) + day_of_year;

const time_t seconds_in_day = 3600 * 24;
const time_t result = seconds_in_day * days_since_epoch + 3600 * t->tm_hour +
60 * t->tm_min + t->tm_sec;
const time_t seconds_in_day = static_cast<const time_t>(3600 * 24);
const time_t result = seconds_in_day * days_since_epoch +
static_cast<time_t>(3600 * t->tm_hour) +
static_cast<time_t>(60 * t->tm_min) + t->tm_sec;

return result;
}
Expand Down
4 changes: 2 additions & 2 deletions CesiumGeometry/src/QuadtreeRectangleAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ QuadtreeRectangleAvailability::QuadtreeRectangleAvailability(
uint32_t maximumLevel) noexcept
: _tilingScheme(tilingScheme),
_maximumLevel(maximumLevel),
_rootNodes(
_rootNodes(static_cast<size_type>(
this->_tilingScheme.getRootTilesX() *
this->_tilingScheme.getRootTilesY()) {
this->_tilingScheme.getRootTilesY())) {
for (uint32_t j = 0; j < this->_tilingScheme.getRootTilesY(); ++j) {
const uint32_t rowStart = j * this->_tilingScheme.getRootTilesX();
for (uint32_t i = 0; i < this->_tilingScheme.getRootTilesX(); ++i) {
Expand Down
6 changes: 4 additions & 2 deletions CesiumGltf/src/Accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <CesiumGltf/BufferView.h>

#include <cstddef>
#include <cstdint>
#include <string>

Expand Down Expand Up @@ -82,7 +83,8 @@ Accessor::computeByteStride(const CesiumGltf::Model& model) const noexcept {
if (pBufferView->byteStride && pBufferView->byteStride.value() != 0) {
return pBufferView->byteStride.value();
}
return computeNumberOfComponents(this->type) *
computeByteSizeOfComponent(this->componentType);
return static_cast<int64_t>(
computeNumberOfComponents(this->type) *
computeByteSizeOfComponent(this->componentType));
}
} // namespace CesiumGltf
3 changes: 2 additions & 1 deletion CesiumGltf/src/TextureView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ std::vector<uint8_t> TextureView::sampleNearestPixel(
static_cast<int64_t>(image.height) - 1);

int64_t pixelIndex =
image.bytesPerChannel * image.channels * (y * image.width + x);
static_cast<int64_t>(image.bytesPerChannel * image.channels) *
(y * image.width + x);

// TODO: Currently stb only outputs uint8 pixel types. If that
// changes this should account for additional pixel byte sizes.
Expand Down
8 changes: 4 additions & 4 deletions CesiumGltfReader/src/decodeDraco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ void copyDecodedIndices(
return;
}

if (pIndicesAccessor->count != pMesh->num_faces() * 3) {
if (pIndicesAccessor->count != static_cast<int64_t>(pMesh->num_faces() * 3)) {
readGltf.warnings.emplace_back(
"indices accessor doesn't match with decoded Draco indices");
pIndicesAccessor->count = pMesh->num_faces() * 3;
pIndicesAccessor->count = static_cast<int64_t>(pMesh->num_faces() * 3);
}

draco::PointIndex::ValueType numPoint = pMesh->num_points();
Expand Down Expand Up @@ -237,8 +237,8 @@ void copyDecodedAttribute(
CesiumGltf::Buffer& buffer = model.buffers.emplace_back();

const int8_t numberOfComponents = pAccessor->computeNumberOfComponents();
const int64_t stride =
numberOfComponents * pAccessor->computeByteSizeOfComponent();
const int64_t stride = static_cast<const int64_t>(
numberOfComponents * pAccessor->computeByteSizeOfComponent());
const int64_t sizeBytes = pAccessor->count * stride;

buffer.cesium.data.resize(static_cast<size_t>(sizeBytes));
Expand Down
2 changes: 1 addition & 1 deletion CesiumGltfReader/test/TestGltfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ TEST_CASE("GltfReader::loadGltf") {
const CesiumGltf::Image& image = result.model->images[0];
CHECK(image.pAsset->width == 2048);
CHECK(image.pAsset->height == 2048);
CHECK(image.pAsset->pixelData.size() == 2048 * 2048 * 4);
CHECK(image.pAsset->pixelData.size() == static_cast<size_type>(2048 * 2048 * 4);

CHECK(!result.model->buffers.empty());
for (const CesiumGltf::Buffer& buffer : result.model->buffers) {
Expand Down
26 changes: 16 additions & 10 deletions CesiumQuantizedMeshTerrain/src/QuantizedMeshLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ static std::optional<QuantizedMeshView> parseQuantizedMesh(
// read the west edge indices
meshView.westEdgeIndicesCount = readValue<uint32_t>(data, readIndex, 0);
readIndex += sizeof(uint32_t);
edgeByteSizes = meshView.westEdgeIndicesCount * indexSizeBytes;
edgeByteSizes =
static_cast<size_t>(meshView.westEdgeIndicesCount * indexSizeBytes);
if (readIndex + edgeByteSizes > data.size()) {
return std::nullopt;
}
Expand All @@ -282,7 +283,8 @@ static std::optional<QuantizedMeshView> parseQuantizedMesh(
// read the south edge
meshView.southEdgeIndicesCount = readValue<uint32_t>(data, readIndex, 0);
readIndex += sizeof(uint32_t);
edgeByteSizes = meshView.southEdgeIndicesCount * indexSizeBytes;
edgeByteSizes =
static_cast<size_t>(meshView.southEdgeIndicesCount * indexSizeBytes);
if (readIndex + edgeByteSizes > data.size()) {
return std::nullopt;
}
Expand All @@ -294,7 +296,8 @@ static std::optional<QuantizedMeshView> parseQuantizedMesh(
// read the east edge
meshView.eastEdgeIndicesCount = readValue<uint32_t>(data, readIndex, 0);
readIndex += sizeof(uint32_t);
edgeByteSizes = meshView.eastEdgeIndicesCount * indexSizeBytes;
edgeByteSizes =
static_cast<size_t>(meshView.eastEdgeIndicesCount * indexSizeBytes);
if (readIndex + edgeByteSizes > data.size()) {
return std::nullopt;
}
Expand All @@ -306,7 +309,8 @@ static std::optional<QuantizedMeshView> parseQuantizedMesh(
// read the north edge
meshView.northEdgeIndicesCount = readValue<uint32_t>(data, readIndex, 0);
readIndex += sizeof(uint32_t);
edgeByteSizes = meshView.northEdgeIndicesCount * indexSizeBytes;
edgeByteSizes =
static_cast<size_t>(meshView.northEdgeIndicesCount * indexSizeBytes);
if (readIndex + edgeByteSizes > data.size()) {
return std::nullopt;
}
Expand All @@ -330,12 +334,13 @@ static std::optional<QuantizedMeshView> parseQuantizedMesh(

if (extensionID == 1) {
// Oct-encoded per-vertex normals
if (readIndex + vertexCount * 2 > data.size()) {
if (readIndex + static_cast<size_t>(vertexCount * 2) > data.size()) {
break;
}

meshView.octEncodedNormalBuffer =
std::span<const std::byte>(data.data() + readIndex, vertexCount * 2);
meshView.octEncodedNormalBuffer = std::span<const std::byte>(
data.data() + readIndex,
static_cast<size_type>(vertexCount * 2));
} else if (enableWaterMask && extensionID == 2) {
// Water Mask
if (extensionLength == 1) {
Expand Down Expand Up @@ -410,7 +415,7 @@ static void addSkirt(
const double north = rectangle.getNorth();

size_t newEdgeIndex = currentVertexCount;
size_t positionIdx = currentVertexCount * 3;
size_t positionIdx = static_cast<size_t>(currentVertexCount * 3);
size_t indexIdx = currentIndicesCount;
for (size_t i = 0; i < edgeIndices.size(); ++i) {
E edgeIdx = edgeIndices[i];
Expand Down Expand Up @@ -726,10 +731,11 @@ static std::vector<std::byte> generateNormals(
// decode position without skirt, but preallocate position buffer to include
// skirt as well
std::vector<std::byte> outputPositionsBuffer(
(vertexCount + skirtVertexCount) * 3 * sizeof(float));
static_cast<unsigned long>((vertexCount + skirtVertexCount) * 3) *
sizeof(float));
std::span<float> outputPositions(
reinterpret_cast<float*>(outputPositionsBuffer.data()),
(vertexCount + skirtVertexCount) * 3);
static_cast<size_type>((vertexCount + skirtVertexCount) * 3));
size_t positionOutputIndex = 0;

const glm::dvec3 center(
Expand Down
22 changes: 14 additions & 8 deletions CesiumQuantizedMeshTerrain/test/TestQuantizedMeshContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void checkGridMesh(
int32_t v = 0;

std::vector<glm::dvec2> uvs;
uvs.reserve(verticesWidth * verticesHeight);
uvs.reserve(static_cast<size_type>(verticesWidth * verticesHeight));
uint32_t positionIdx = 0;
uint32_t idx = 0;
for (uint32_t y = 0; y < verticesHeight; ++y) {
Expand Down Expand Up @@ -491,8 +491,10 @@ void checkGridMesh(
size_t eastIndicesCount = quantizedMesh.vertexData.eastIndices.size();
size_t northIndicesCount = quantizedMesh.vertexData.northIndices.size();

size_t gridVerticesCount = verticesWidth * verticesHeight;
size_t gridIndicesCount = (verticesHeight - 1) * (verticesWidth - 1) * 6;
size_t gridVerticesCount =
static_cast<size_t>(verticesWidth * verticesHeight);
size_t gridIndicesCount =
static_cast<size_t>((verticesHeight - 1) * (verticesWidth - 1) * 6);
size_t totalSkirtVertices = westIndicesCount + southIndicesCount +
eastIndicesCount + northIndicesCount;
size_t totalSkirtIndices = (totalSkirtVertices - 4) * 6;
Expand Down Expand Up @@ -593,7 +595,8 @@ static void checkGeneratedGridNormal(
uint32_t verticesWidth,
uint32_t verticesHeight) {
uint32_t totalGridIndices = (verticesWidth - 1) * (verticesHeight - 1) * 6;
std::vector<glm::vec3> expectedNormals(verticesWidth * verticesHeight);
std::vector<glm::vec3> expectedNormals(
static_cast<size_type>(verticesWidth * verticesHeight));
for (uint32_t i = 0; i < totalGridIndices; i += 3) {
I id0 = indices[i];
I id1 = indices[i + 1];
Expand Down Expand Up @@ -639,7 +642,8 @@ static void checkGeneratedGridNormal(
size_t eastIndicesCount = quantizedMesh.vertexData.eastIndices.size();
size_t northIndicesCount = quantizedMesh.vertexData.northIndices.size();

size_t gridVerticesCount = verticesWidth * verticesHeight;
size_t gridVerticesCount =
static_cast<size_t>(verticesWidth * verticesHeight);
size_t totalSkirtVertices = westIndicesCount + southIndicesCount +
eastIndicesCount + northIndicesCount;

Expand Down Expand Up @@ -1026,7 +1030,8 @@ TEST_CASE("Test converting quantized mesh to gltf with skirt") {
glm::vec3 normal = glm::normalize(glm::vec3(0.2, 1.4, 0.3));
uint8_t x = 0, y = 0;
octEncode(normal, x, y);
std::vector<std::byte> octNormals(verticesWidth * verticesHeight * 2);
std::vector<std::byte> octNormals(
static_cast<size_type>(verticesWidth * verticesHeight * 2));
for (size_t i = 0; i < octNormals.size(); i += 2) {
octNormals[i] = std::byte(x);
octNormals[i + 1] = std::byte(y);
Expand Down Expand Up @@ -1068,7 +1073,7 @@ TEST_CASE("Test converting quantized mesh to gltf with skirt") {

REQUIRE(
static_cast<size_t>(normals.size()) ==
(verticesWidth * verticesHeight + totalSkirtVerticesCount));
(static_cast<size_t>(verticesWidth * verticesHeight + totalSkirtVerticesCount));
for (int64_t i = 0; i < normals.size(); ++i) {
REQUIRE(Math::equalsEpsilon(normals[i].x, normal.x, Math::Epsilon2));
REQUIRE(Math::equalsEpsilon(normals[i].y, normal.y, Math::Epsilon2));
Expand Down Expand Up @@ -1113,7 +1118,8 @@ TEST_CASE("Test converting ill-formed quantized mesh") {
glm::vec3 normal = glm::normalize(glm::vec3(0.2, 1.4, 0.3));
uint8_t x = 0, y = 0;
octEncode(normal, x, y);
std::vector<std::byte> octNormals(verticesWidth * verticesHeight * 2);
std::vector<std::byte> octNormals(
static_cast<size_type>(verticesWidth * verticesHeight * 2));
for (size_t i = 0; i < octNormals.size(); i += 2) {
octNormals[i] = std::byte(x);
octNormals[i + 1] = std::byte(y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <spdlog/fwd.h>

#include <any>
#include <cstddef>
#include <functional>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -50,7 +51,7 @@ struct CESIUMRASTEROVERLAYS_API RasterOverlayOptions {
* in memory in case they're needed again soon. This property controls the
* maximum size of that cache.
*/
int64_t subTileCacheBytes = 16 * 1024 * 1024;
int64_t subTileCacheBytes = static_cast<int64_t>(16 * 1024 * 1024);

/**
* @brief The maximum pixel size of raster overlay textures, in either
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class TestTileProvider : public QuadtreeRasterOverlayTileProvider {
result.pImage->bytesPerChannel = 1;
result.pImage->channels = 4;
result.pImage->pixelData.resize(
this->getWidth() * this->getHeight() * 4,
static_cast<size_type>(this->getWidth() * this->getHeight() * 4),
std::byte(tileID.level));
}

Expand Down
2 changes: 1 addition & 1 deletion cmake/macros/setup_clang_tidy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function(setup_clang_tidy)
${_PROJECT_BUILD_DIRECTORY} # path that contains a compile_commands.json
)
add_custom_target(
clang-tidy-fix COMMAND ${CLANG_TIDY_RUNNER_PATH} -fix -extra-arg=-Wno-unknown-warning-option -clang-tidy-binary ${CLANG_TIDY_PATH} -p
clang-tidy-fix COMMAND ${CLANG_TIDY_RUNNER_PATH} -fix -extra-arg=-Wno-unknown-warning-option -j14 -clang-tidy-binary ${CLANG_TIDY_PATH} -p
${_PROJECT_BUILD_DIRECTORY} # path that contains a compile_commands.json
)
else()
Expand Down

0 comments on commit 7ef48d5

Please sign in to comment.