Skip to content

Commit

Permalink
cppcheck fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Oct 14, 2024
1 parent 19ab95f commit c8214ad
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 49 deletions.
2 changes: 2 additions & 0 deletions cmake/cppcheck-suppression-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ shadowFunction:*/src/vsg/state/Image.cpp
shadowFunction:*/src/vsg/state/ImageView.cpp
shadowFunction:*/src/vsg/state/MultisampleState.cpp
shadowFunction:*/src/vsg/state/DescriptorImage.cpp
shadowFunction:*/src/vsg/utils/FindDynamicObjects.cpp


// suppress unhelpful warning of c casts
cstyleCast:*/include/vsg/io/mem_stream.h
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/ImageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int ImageInfo::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_pointer(sampler, rhs.sampler))) return result;
if ((result = compare_pointer(imageView, rhs.imageView))) return result;
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/MultisampleState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int MultisampleState::compare(const Object& rhs_object) const
int result = GraphicsPipelineState::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_value(rasterizationSamples, rhs.rasterizationSamples))) return result;
if ((result = compare_value(sampleShadingEnable, rhs.sampleShadingEnable))) return result;
Expand Down
6 changes: 3 additions & 3 deletions src/vsg/state/PipelineLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int PipelineLayout::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_value(flags, rhs.flags))) return result;
if ((result = compare_pointer_container(setLayouts, rhs.setLayouts))) return result;
Expand Down Expand Up @@ -86,13 +86,13 @@ void PipelineLayout::write(Output& output) const
output.writeValue<uint32_t>("flags", flags);

output.writeValue<uint32_t>("setLayouts", setLayouts.size());
for (auto& descriptorLayout : setLayouts)
for (const auto& descriptorLayout : setLayouts)
{
output.writeObject("descriptorLayout", descriptorLayout);
}

output.writeValue<uint32_t>("pushConstantRanges", pushConstantRanges.size());
for (auto& pushConstantRange : pushConstantRanges)
for (const auto& pushConstantRange : pushConstantRanges)
{
output.writeValue<uint32_t>("stageFlags", pushConstantRange.stageFlags);
output.write("offset", pushConstantRange.offset);
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/RasterizationState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int RasterizationState::compare(const Object& rhs_object) const
int result = GraphicsPipelineState::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);
return compare_region(depthClampEnable, lineWidth, rhs.depthClampEnable);
}

Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/Sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int Sampler::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);
return compare_region(flags, unnormalizedCoordinates, rhs.flags);
}

Expand Down
4 changes: 2 additions & 2 deletions src/vsg/state/ShaderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int ShaderCompileSettings::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_value(vulkanVersion, rhs.vulkanVersion))) return result;
if ((result = compare_value(clientInputVersion, rhs.clientInputVersion))) return result;
Expand Down Expand Up @@ -108,7 +108,7 @@ int ShaderModule::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_value(source, rhs.source))) return result;
if ((result = compare_pointer(hints, rhs.hints))) return result;
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/StateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int StateCommand::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);
return compare_value(slot, rhs.slot);
}

Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/TessellationState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int TessellationState::compare(const Object& rhs_object) const
int result = GraphicsPipelineState::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);
return compare_value(patchControlPoints, rhs.patchControlPoints);
}

Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/VertexInputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int VertexInputState::compare(const Object& rhs_object) const
int result = GraphicsPipelineState::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_value_container(vertexBindingDescriptions, rhs.vertexBindingDescriptions))) return result;
return compare_value_container(vertexAttributeDescriptions, rhs.vertexAttributeDescriptions);
Expand Down
10 changes: 5 additions & 5 deletions src/vsg/state/ViewDependentState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int ViewDescriptorSetLayout::compare(const Object& rhs_object) const
int result = DescriptorSetLayout::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);
return compare_pointer(_viewDescriptorSetLayout, rhs._viewDescriptorSetLayout);
}

Expand Down Expand Up @@ -119,7 +119,7 @@ int BindViewDescriptorSets::compare(const Object& rhs_object) const
int result = StateCommand::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_value(pipelineBindPoint, rhs.pipelineBindPoint))) return result;
if ((result = compare_pointer(layout, rhs.layout))) return result;
Expand Down Expand Up @@ -229,7 +229,7 @@ void ViewDependentState::init(ResourceRequirements& requirements)
uint32_t shadowHeight = 2048;
uint32_t maxShadowMaps = 8;

auto& viewDetails = requirements.views[view];
const auto& viewDetails = requirements.views[view];

if ((view->features & (RECORD_LIGHTS | RECORD_SHADOW_MAPS)) != 0)
{
Expand Down Expand Up @@ -448,7 +448,7 @@ void ViewDependentState::compile(Context& context)
shadowDepthImage->compile(context);

uint32_t layer = 0;
for (auto& shadowMap : shadowMaps)
for (const auto& shadowMap : shadowMaps)
{
// create depth buffer
auto depthImageView = ImageView::create(shadowDepthImage, VK_IMAGE_ASPECT_DEPTH_BIT);
Expand Down Expand Up @@ -686,7 +686,7 @@ void ViewDependentState::traverse(RecordTraversal& rt) const

// lightData requirements = vec4 * (num_ambientLights + 3 * num_directionLights + 3 * num_pointLights + 4 * num_spotLights + 4 * num_shadow_maps)

for (auto& entry : ambientLights)
for (const auto& entry : ambientLights)
{
auto light = entry.second;
(*light_itr++).set(light->color.r, light->color.g, light->color.b, light->intensity);
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/ViewportState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int ViewportState::compare(const Object& rhs_object) const
int result = GraphicsPipelineState::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_value_container(viewports, rhs.viewports))) return result;
return compare_value_container(scissors, rhs.scissors);
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/text/CpuLayoutTechnique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ref_ptr<Node> CpuLayoutTechnique::createRenderingSubgraph(ref_ptr<ShaderSet> sha
bool singleOutlineColor = true;
bool singleOutlineWidth = true;
bool singleCenterAutoScaleDistance = true;
for (auto& quad : quads)
for (const auto& quad : quads)
{
for (int i = 0; i < 4; ++i)
{
Expand Down
6 changes: 3 additions & 3 deletions src/vsg/text/GpuLayoutTechnique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void GpuLayoutTechnique::setup(Text* text, uint32_t minimumAllocation, ref_ptr<c
allocate(static_cast<uint32_t>(text.valueCount()));

auto itr = textArray->begin();
for (auto& c : text)
for (const auto& c : text)
{
assignValue(*(itr++), font.glyphIndexForCharcode(c), updated);
}
Expand All @@ -121,7 +121,7 @@ void GpuLayoutTechnique::setup(Text* text, uint32_t minimumAllocation, ref_ptr<c
allocate(static_cast<uint32_t>(text.valueCount()));

auto itr = textArray->begin();
for (auto& c : text)
for (const auto& c : text)
{
assignValue(*(itr++), font.glyphIndexForCharcode(c), updated);
}
Expand All @@ -131,7 +131,7 @@ void GpuLayoutTechnique::setup(Text* text, uint32_t minimumAllocation, ref_ptr<c
allocate(static_cast<uint32_t>(text.valueCount()));

auto itr = textArray->begin();
for (auto& c : text)
for (const auto& c : text)
{
assignValue(*(itr++), font.glyphIndexForCharcode(c), updated);
}
Expand Down
32 changes: 16 additions & 16 deletions src/vsg/text/StandardLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,35 @@ namespace

void apply(const stringValue& text) override
{
for (auto& c : text.value())
for (const auto& c : text.value())
{
character(uint8_t(c));
}
}
void apply(const wstringValue& text) override
{
for (auto& c : text.value())
for (const auto& c : text.value())
{
character(uint16_t(c));
}
}
void apply(const ubyteArray& text) override
{
for (auto& c : text)
for (const auto& c : text)
{
character(c);
}
}
void apply(const ushortArray& text) override
{
for (auto& c : text)
for (const auto& c : text)
{
character(c);
}
}
void apply(const uintArray& text) override
{
for (auto& c : text)
for (const auto& c : text)
{
character(c);
}
Expand Down Expand Up @@ -398,15 +398,15 @@ void StandardLayout::layout(const Data* text, const Font& font, TextQuads& quads

if (layout.horizontalAlignment != BASELINE_ALIGNMENT || layout.verticalAlignment != BASELINE_ALIGNMENT)
{
vec2 alignment(0.0f, 0.0f);
vec2 glyphAlignment(0.0f, 0.0f);

float left = textQuads[start_of_conversion].vertices[0].x;
float right = textQuads[start_of_conversion].vertices[1].x;
float bottom = textQuads[start_of_conversion].vertices[0].y;
float top = textQuads[start_of_conversion].vertices[3].y;
for (size_t i = start_of_conversion + 1; i < textQuads.size(); ++i)
{
auto& quad = textQuads[i];
const auto& quad = textQuads[i];
if (quad.vertices[0].x < left) left = quad.vertices[0].x;
if (quad.vertices[1].x > right) right = quad.vertices[1].x;
if (quad.vertices[0].y < bottom) bottom = quad.vertices[0].y;
Expand All @@ -415,21 +415,21 @@ void StandardLayout::layout(const Data* text, const Font& font, TextQuads& quads

switch (layout.horizontalAlignment)
{
case (BASELINE_ALIGNMENT): alignment.x = 0.0f; break;
case (LEFT_ALIGNMENT): alignment.x = -left; break;
case (CENTER_ALIGNMENT): alignment.x = -(right + left) * 0.5f; break;
case (RIGHT_ALIGNMENT): alignment.x = -right; break;
case (BASELINE_ALIGNMENT): glyphAlignment.x = 0.0f; break;
case (LEFT_ALIGNMENT): glyphAlignment.x = -left; break;
case (CENTER_ALIGNMENT): glyphAlignment.x = -(right + left) * 0.5f; break;
case (RIGHT_ALIGNMENT): glyphAlignment.x = -right; break;
}

switch (layout.verticalAlignment)
{
case (BASELINE_ALIGNMENT): alignment.y = 0.0f; break;
case (TOP_ALIGNMENT): alignment.y = -top; break;
case (CENTER_ALIGNMENT): alignment.y = -(bottom + top) * 0.5f; break;
case (BOTTOM_ALIGNMENT): alignment.y = -bottom; break;
case (BASELINE_ALIGNMENT): glyphAlignment.y = 0.0f; break;
case (TOP_ALIGNMENT): glyphAlignment.y = -top; break;
case (CENTER_ALIGNMENT): glyphAlignment.y = -(bottom + top) * 0.5f; break;
case (BOTTOM_ALIGNMENT): glyphAlignment.y = -bottom; break;
}

offset = layout.horizontal * alignment.x + layout.vertical * alignment.y;
offset = layout.horizontal * glyphAlignment.x + layout.vertical * glyphAlignment.y;
}

if (!layout.billboard)
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/text/TextGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int TextGroup::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);
return compare_pointer_container(children, rhs.children);
}

Expand Down
4 changes: 2 additions & 2 deletions src/vsg/threading/OperationThreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ OperationThreads::OperationThreads(uint32_t numThreads, ref_ptr<ActivityStatus>
if (!status) status = ActivityStatus::create();
queue = OperationQueue::create(status);

auto run = [](ref_ptr<OperationQueue> q, ref_ptr<ActivityStatus> thread_status) {
auto runThread = [](ref_ptr<OperationQueue> q, ref_ptr<ActivityStatus> thread_status) {
while (thread_status->active())
{
ref_ptr<Operation> operation = q->take_when_available();
Expand All @@ -34,7 +34,7 @@ OperationThreads::OperationThreads(uint32_t numThreads, ref_ptr<ActivityStatus>

for (size_t i = 0; i < numThreads; ++i)
{
threads.emplace_back(run, queue, status);
threads.emplace_back(runThread, queue, status);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/vsg/utils/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ref_ptr<StateGroup> Builder::createStateGroup(const StateInfo& stateInfo)
graphicsPipelineConfig->assignTexture("displacementMap", stateInfo.displacementMap, sampler);
}

if (auto& materialBinding = activeShaderSet->getDescriptorBinding("material"))
if (const auto& materialBinding = activeShaderSet->getDescriptorBinding("material"))
{
ref_ptr<Data> mat = materialBinding.data;
if (!mat) mat = vsg::PhongMaterialValue::create();
Expand Down Expand Up @@ -247,7 +247,7 @@ ref_ptr<Node> Builder::decorateAndCompileIfRequired(const GeometryInfo& info, co
if (auto v3a = info.positions.cast<vec3Array>())
{
box bound;
for (auto& v : *v3a)
for (const auto& v : *v3a)
{
bound.add(v);
}
Expand Down
12 changes: 6 additions & 6 deletions src/vsg/utils/GraphicsPipelineConfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int DescriptorConfigurator::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_pointer(shaderSet, rhs.shaderSet))) return result;
if ((result = compare_value(blending, rhs.blending))) return result;
Expand Down Expand Up @@ -252,7 +252,7 @@ bool DescriptorConfigurator::assignDefaults(const std::set<uint32_t>& inheritedS
if (descriptorBinding.define.empty() && assigned.count(descriptorBinding.name) == 0)
{
bool set_matched = false;
for (auto& cds : shaderSet->customDescriptorSetBindings)
for (const auto& cds : shaderSet->customDescriptorSetBindings)
{
if (cds->set == descriptorBinding.set)
{
Expand Down Expand Up @@ -310,7 +310,7 @@ int ArrayConfigurator::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_pointer(shaderSet, rhs.shaderSet))) return result;
if ((result = compare_value(baseAttributeBinding, rhs.baseAttributeBinding))) return result;
Expand Down Expand Up @@ -493,7 +493,7 @@ int GraphicsPipelineConfigurator::compare(const Object& rhs_object) const
int result = Object::compare(rhs_object);
if (result != 0) return result;

auto& rhs = static_cast<decltype(*this)>(rhs_object);
const auto& rhs = static_cast<decltype(*this)>(rhs_object);

if ((result = compare_pointer_container(pipelineStates, rhs.pipelineStates))) return result;

Expand Down Expand Up @@ -599,7 +599,7 @@ bool GraphicsPipelineConfigurator::copyTo(StateCommands& stateCommands, ref_ptr<
bool stateAssigned = false;

bool pipelineUnique = true;
for (auto& sc : inheritedState)
for (const auto& sc : inheritedState)
{
if (compare_pointer(sc, bindGraphicsPipeline) == 0) pipelineUnique = false;
}
Expand Down Expand Up @@ -632,7 +632,7 @@ bool GraphicsPipelineConfigurator::copyTo(StateCommands& stateCommands, ref_ptr<
auto bindDescriptorSet = BindDescriptorSet::create(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, static_cast<uint32_t>(set), ds);

bool dsUnique = true;
for (auto& sc : inheritedState)
for (const auto& sc : inheritedState)
{
if (compare_pointer(sc, bindDescriptorSet) == 0) dsUnique = false;
}
Expand Down

0 comments on commit c8214ad

Please sign in to comment.