Skip to content

Commit

Permalink
Fixes for AddressSanitizer stack-use-after-scope errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenCzarnecki committed Jan 14, 2025
1 parent e31563a commit 9d6b867
Show file tree
Hide file tree
Showing 20 changed files with 238 additions and 134 deletions.
12 changes: 7 additions & 5 deletions src/MultiLayerOptics/src/AbsorptancesMultiPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace MultiLayerOptics
void CAbsorptancesMultiPane::calculateRTCoefficients()
{
const size_t size{m_T.size()};

for(const auto side : EnumSide())
EnumSide sides;
for(const auto side : sides)
{
const auto oppositeSide{FenestrationCommon::oppositeSide(side)};

Expand Down Expand Up @@ -96,8 +96,9 @@ namespace MultiLayerOptics
{
// Calculate normalized radiances
const auto wv{m_T[0].getXArray()};

for(const auto side : EnumSide())

EnumSide sides;
for(const auto side : sides)
{
const size_t size{m_rCoeffs.at(side).size()};

Expand Down Expand Up @@ -126,7 +127,8 @@ namespace MultiLayerOptics

void CAbsorptancesMultiPane::calculateAbsorptances()
{
for(const auto side : EnumSide())
EnumSide sides;
for(const auto side : sides)
{
const auto oppositeSide{FenestrationCommon::oppositeSide(side)};
const size_t size{Iminus.at(side).size()};
Expand Down
12 changes: 8 additions & 4 deletions src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ namespace MultiLayerOptics

void CEquivalentBSDFLayer::calculate()
{
for(Side aSide : FenestrationCommon::EnumSide())
FenestrationCommon::EnumSide sides;
for(Side aSide : sides)
{
m_TotA[aSide] =
CMatrixSeries(m_Layer.size(), m_Lambda.size(), m_CombinedLayerWavelengths.size());
m_TotJSC[aSide] =
CMatrixSeries(m_Layer.size(), m_Lambda.size(), m_CombinedLayerWavelengths.size());
for(PropertySimple aProperty : FenestrationCommon::EnumPropertySimple())
FenestrationCommon::EnumPropertySimple properties;
for(PropertySimple aProperty : properties)
{
m_Tot[{aSide, aProperty}] = CMatrixSeries(
m_Lambda.size(), m_Lambda.size(), m_CombinedLayerWavelengths.size());
Expand All @@ -129,7 +131,8 @@ namespace MultiLayerOptics
// getEquivalentLayerAtWavelength is calculation intensive and it will slow down the
// execution
auto layer{getEquivalentLayerAtWavelength(index)};
for(auto aSide : FenestrationCommon::EnumSide())
FenestrationCommon::EnumSide sides;
for(auto aSide : sides)
{
for(size_t layerNumber = 0; layerNumber < m_Layer.size(); ++layerNumber)
{
Expand All @@ -145,7 +148,8 @@ namespace MultiLayerOptics
m_CombinedLayerWavelengths[index],
layer.getLayerJSC(layerNumber + 1, aSide));
}
for(auto aProperty : FenestrationCommon::EnumPropertySimple())
FenestrationCommon::EnumPropertySimple properties;
for(auto aProperty : properties)
{
m_Tot.at({aSide, aProperty})
.setPropertiesAtIndex(index,
Expand Down
9 changes: 6 additions & 3 deletions src/MultiLayerOptics/src/EquivalentBSDFLayerSingleBand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ namespace MultiLayerOptics
std::vector<double>(t_Layer.lambdaVector().size(), 0));
}
m_EquivalentLayer = BSDFIntegrator(t_Layer);
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
m_A[aSide] = std::vector<std::vector<double>>();
m_JSC[aSide] = std::vector<std::vector<double>>();
Expand Down Expand Up @@ -187,7 +188,8 @@ namespace MultiLayerOptics
std::vector<double>(t_Layer.lambdaVector().size(), 0));
}
m_PropertiesCalculated = false;
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
m_A.at(aSide).clear();
m_JSC.at(aSide).clear();
Expand Down Expand Up @@ -289,7 +291,8 @@ namespace MultiLayerOptics
{
for(size_t i = 0; i < numberOfLayers; i++)
{
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
auto AbsFront{m_Layers[i].Abs(aSide)};
auto AbsBack{m_Layers[i].Abs(oppositeSide(aSide))};
Expand Down
16 changes: 10 additions & 6 deletions src/MultiLayerOptics/src/MultiLayerInterRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ namespace MultiLayerOptics
{
// Sum of previous two components. Total diffuse energy that gets off the surfaces.
CSurfaceEnergy diffSum{};

for(EnergyFlow aEnergyFlow : EnumEnergyFlow())
EnumEnergyFlow energyFlows;
for(EnergyFlow aEnergyFlow : energyFlows)
{
for(size_t i = 1; i <= m_Layers.size(); ++i)
{ // Layer indexing goes from one
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
Side oppSide = oppositeSide(aSide);
// Calculate diffuse energy from direct exterior/interior beam
Expand Down Expand Up @@ -212,7 +213,8 @@ namespace MultiLayerOptics
CSurfaceEnergy aScatter{};

// Calculate total energy scatterred from beam to diffuse
for(EnergyFlow aEnergyFlow : EnumEnergyFlow())
EnumEnergyFlow energyFlows;
for(EnergyFlow aEnergyFlow : energyFlows)
{
// In this case numbering goes through gas environments (gaps, interior and exterior)
// becase we want to keep interreflectance calculations together
Expand Down Expand Up @@ -265,11 +267,13 @@ namespace MultiLayerOptics
{
for(size_t i = 0; i < m_Layers.size(); ++i)
{
for(EnergyFlow aEnergyFlow : EnumEnergyFlow())
EnumEnergyFlow energyFlows;
for(EnergyFlow aEnergyFlow : energyFlows)
{
double EnergyDirect = 0;
double EnergyDiffuse = 0;
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
const double Adir =
m_Layers[i].getAbsorptance(aSide, ScatteringSimple::Direct, t_Theta, t_Phi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ namespace MultiLayerOptics
///////////////////////////////////////////////////////////////////////////////////////////////////////////
CSurfaceEnergy::CSurfaceEnergy()
{
for(Side t_Side : EnumSide())
EnumSide sides;
for(Side t_Side : sides)
{
for(EnergyFlow t_EnergyFlow : EnumEnergyFlow())
EnumEnergyFlow flows;
for(EnergyFlow t_EnergyFlow : flows)
{
m_IEnergy[std::make_pair(t_Side, t_EnergyFlow)] =
std::make_shared<std::vector<double>>();
Expand Down Expand Up @@ -112,7 +114,8 @@ namespace MultiLayerOptics
// Even if energy flow comes from one side, it still hits both sides of the layer and
// this loop calculates energy absorbed at each side
double absTot = 0;
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
absTot += m_Layers[Index - 1].getProperty(Property::Abs, aSide)
* getEnergyToSurface(Index, aSide, aFlow);
Expand Down
8 changes: 5 additions & 3 deletions src/MultiLayerOptics/src/MultiPaneBSDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ namespace MultiLayerOptics

m_IncomingSolar = calculateIncomingSolar(m_IncomingSpectra, minLambda, maxLambda);

for(Side aSide : FenestrationCommon::EnumSide())
FenestrationCommon::EnumSide sides;
for(Side aSide : sides)
{
m_Abs[aSide] = calculateAbsorptance(aSide, minLambda, maxLambda);
m_AbsElectricity[aSide] = calculateJSC(aSide, minLambda, maxLambda);

std::map<std::pair<Side, PropertySimple>, SquareMatrix> aResults;
for(PropertySimple aProperty : FenestrationCommon::EnumPropertySimple())
FenestrationCommon::EnumPropertySimple properties;
for(PropertySimple aProperty : properties)
{
aResults[{aSide, aProperty}] =
calculateProperties(aSide, aProperty, minLambda, maxLambda);
Expand All @@ -199,7 +201,7 @@ namespace MultiLayerOptics

m_Results.resetCalculatedResults();

for(const Side aSide : FenestrationCommon::EnumSide())
for(Side aSide : sides)
{
calcHemisphericalAbs(aSide);
}
Expand Down
9 changes: 6 additions & 3 deletions src/MultiLayerOptics/src/MultiPaneSampleData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ namespace MultiLayerOptics
(*it)->properties(Property ::R, Side::Back));
}

for(const auto & prop : EnumProperty())
EnumProperty properties;
for(const auto & prop : properties)
{
for(const auto side : EnumSide())
EnumSide sides;
for(const auto side : sides)
{
m_Property[std::make_pair(prop, side)] = aEqivalentLayer.getProperties(prop, side);
}
}

for(const auto side : EnumSide())
EnumSide sides;
for(const auto side : sides)
{
m_LayerAbsorptances.at(side).clear();
size_t size = aAbsorptances.numOfLayers();
Expand Down
6 changes: 4 additions & 2 deletions src/MultiLayerOptics/src/MultiPaneSpectralSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace MultiLayerOptics
{
if(!m_StateCalculated)
{
for(const auto side : EnumSide())
EnumSide sides;
for(const auto side : sides)
{
CSpectralSample::calculateProperties(integrator, normalizationCoefficient);
if(std::dynamic_pointer_cast<CMultiPaneSampleData>(m_SampleData) != NULL)
Expand Down Expand Up @@ -95,7 +96,8 @@ namespace MultiLayerOptics
void CMultiPaneSpectralSample::reset()
{
CSpectralSample::reset();
for(const auto side : EnumSide())
EnumSide sides;
for(const auto side : sides)
{
m_AbsorbedLayersSource.at(side).clear();
}
Expand Down
21 changes: 14 additions & 7 deletions src/SingleLayerOptics/src/BSDFIntegrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ namespace SingleLayerOptics
m_DirectHemisphericalCalculated(false),
m_DiffuseDiffuseCalculated(false)
{
for(auto t_Side : EnumSide())
EnumSide sides;
for(auto t_Side : sides)
{
for(auto t_Property : EnumPropertySimple())
EnumPropertySimple properties;
for(auto t_Property : properties)
{
m_Matrix[std::make_pair(t_Side, t_Property)] = SquareMatrix(m_DimMatrices);
m_DirectHemispherical[std::make_pair(t_Side, t_Property)] = std::vector<double>(m_DimMatrices);
Expand Down Expand Up @@ -130,9 +132,11 @@ namespace SingleLayerOptics
{
if(!m_DiffuseDiffuseCalculated)
{
for(auto t_Side : EnumSide())
EnumSide sides;
for(auto t_Side : sides)
{
for(auto t_PropertySimple : EnumPropertySimple())
EnumPropertySimple properties;
for(auto t_PropertySimple : properties)
{
m_DiffDiff(t_Side, t_PropertySimple) =
integrate(getMatrix(t_Side, t_PropertySimple));
Expand All @@ -151,9 +155,11 @@ namespace SingleLayerOptics
{
if(!m_DirectHemisphericalCalculated)
{
for(Side t_Side : EnumSide())
EnumSide sides;
for(auto t_Side : sides)
{
for(PropertySimple t_PropertySimple : EnumPropertySimple())
EnumPropertySimple properties;
for(PropertySimple t_PropertySimple : properties)
{
m_DirectHemispherical[{t_Side, t_PropertySimple}] =
m_Directions.lambdaVector() * m_Matrix.at({t_Side, t_PropertySimple});
Expand All @@ -164,7 +170,8 @@ namespace SingleLayerOptics
const auto size = m_DirectHemispherical[{Side::Front, PropertySimple::T}].size();
for(size_t i = 0; i < size; ++i)
{
for(Side t_Side : EnumSide())
EnumSide sides;
for(auto t_Side : sides)
{
m_Abs.at(t_Side).push_back(1.0 - m_DirectHemispherical.at({t_Side, PropertySimple::T})[i]
- m_DirectHemispherical.at({t_Side, PropertySimple::R})[i]);
Expand Down
18 changes: 12 additions & 6 deletions src/SingleLayerOptics/src/BSDFLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace SingleLayerOptics

void CBSDFLayer::calculate_dir_dir_wl(size_t wavelengthIndex, BSDFIntegrator & results)
{
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
const auto & aDirections = m_BSDFHemisphere.getDirections(BSDFDirection::Incoming);
size_t size = aDirections.size();
Expand All @@ -81,7 +82,8 @@ namespace SingleLayerOptics

void CBSDFLayer::calculate_dir_dif_wv(size_t wavelengthIndex, BSDFIntegrator & results)
{
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
const auto & aDirections = m_BSDFHemisphere.getDirections(BSDFDirection::Incoming);

Expand Down Expand Up @@ -110,7 +112,8 @@ namespace SingleLayerOptics

void CBSDFLayer::calc_dir_dir()
{
for(Side t_Side : EnumSide())
EnumSide sides;
for(Side t_Side : sides)
{
BSDFDirections aDirections = m_BSDFHemisphere.getDirections(BSDFDirection::Incoming);
size_t size = aDirections.size();
Expand All @@ -133,7 +136,8 @@ namespace SingleLayerOptics

void CBSDFLayer::calc_dir_dir_wv(std::vector<BSDFIntegrator> & results)
{
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
const auto & aDirections = m_BSDFHemisphere.getDirections(BSDFDirection::Incoming);
size_t size = aDirections.size();
Expand All @@ -157,7 +161,8 @@ namespace SingleLayerOptics

void CBSDFLayer::calc_dir_dif()
{
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
const auto & aDirections = m_BSDFHemisphere.getDirections(BSDFDirection::Incoming);

Expand All @@ -172,7 +177,8 @@ namespace SingleLayerOptics

void CBSDFLayer::calc_dir_dif_wv(std::vector<BSDFIntegrator> & results)
{
for(Side aSide : EnumSide())
EnumSide sides;
for(Side aSide : sides)
{
const auto & aDirections = m_BSDFHemisphere.getDirections(BSDFDirection::Incoming);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ TEST_F(TestSingleLayerOpticsUtilities, BSDFDirectionEnumeration)
{
using SingleLayerOptics::BSDFDirection;
std::vector<BSDFDirection> directions;
for(const auto & direction : SingleLayerOptics::EnumBSDFDirection())
SingleLayerOptics::EnumBSDFDirection dirs;
for(const auto & direction : dirs)
{
directions.emplace_back(direction);
}
Expand Down
Loading

0 comments on commit 9d6b867

Please sign in to comment.