Conversation
…into cppcheck_continued
SimAirServingZones.cc| int numNoDepend = -1; | ||
| int loopCount = 0; | ||
| while ((numNoDepend != 0) || (loopCount > 100000)) { | ||
| while ((numNoDepend != 0) && (loopCount < 100000)) { |
There was a problem hiding this comment.
I think this loop condition is flipped.
With while ((numNoDepend != 0) || (loopCount > 100000)), the loop would continue once loopCount exceeds the limit, so the post-loop check if (loopCount > 100000) (line 2411) becomes unreachable.
This probably wants && with a max-iteration guard instead, like while ((numNoDepend != 0) && (loopCount < 100000)).
| const auto &FinalSysSizing(state.dataSize->FinalSysSizing); | ||
| auto &EvapCond(state.dataEvapCoolers->EvapCond); | ||
| auto &thisEvapCond(EvapCond(EvapCoolNum)); | ||
| auto &thisEvapCond(state.dataEvapCoolers->EvapCond(EvapCoolNum)); |
There was a problem hiding this comment.
EvapCond itself is only used once and is never modified, and the actual mutable object is thisEvapCond. Rather than making EvapCond a const, it may be cleaner to remove that alias entirely and bind thisEvapCond directly to state.dataEvapCoolers->EvapCond(EvapCoolNum).
| if (!RunFlag) { | ||
| return; | ||
| } | ||
|
|
There was a problem hiding this comment.
The second if (!RunFlag) here is unreachable since the earlier if (!RunFlag) in line 1590 already returns from the function. By the time execution gets here, RunFlag must be true, so this check can be removed.
| } | ||
| if (state.dataEnvrn->PrintEnvrnStampWarmup) { | ||
| if (state.dataReportFlag->PrintEndDataDictionary && state.dataGlobal->DoOutputReporting) { | ||
| if (state.dataReportFlag->PrintEndDataDictionary) { |
There was a problem hiding this comment.
DoOutputReporting is already guaranteed to be true by the enclosing else if condition (line 3356), so the inner check is redundant here. I removed the repeated state.dataGlobal->DoOutputReporting from the nested if condition.
| print(state.files.mtr, "{}\n", EndOfHeaderString); | ||
| state.dataReportFlag->PrintEndDataDictionary = false; | ||
| } | ||
| if (state.dataGlobal->DoOutputReporting) { |
There was a problem hiding this comment.
Same, the repeated state.dataGlobal->DoOutputReporting can be removed.
| } | ||
| if (state.dataEnvrn->PrintEnvrnStampWarmup) { | ||
| if (state.dataReportFlag->PrintEndDataDictionary && state.dataGlobal->DoOutputReporting && !state.dataHVACMgr->PrintedWarmup) { | ||
| if (state.dataReportFlag->PrintEndDataDictionary && !state.dataHVACMgr->PrintedWarmup) { |
There was a problem hiding this comment.
Same as the HeatBalanceManager.cc cases. DoOutputReporting is already guaranteed to be true by the enclosing else if condition (line 479), so the inner checks are redundant here and in the line 493. I removed the repeated state.dataGlobal->DoOutputReporting from the nested if condition.
| PreviousMaxiumHumidOrDehumidOutput = latentRoomORZone; | ||
| } | ||
| } else { | ||
| if (!DidWeMeetLoad) { |
There was a problem hiding this comment.
!DidWeMeetLoad is already guaranteed by the enclosing if (!DidWeMeetLoad && !DidWeMeetHumidificaiton) in line 1544, so the nested if (!DidWeMeetLoad) is redundant here and can be removed.
| CurrentOperatingSettings[1] = oStandBy; | ||
| } else { | ||
| // if we partly met the load then do the best we can and run full out in that optimal setting. | ||
| if (!DidWeMeetLoad && DidWePartlyMeetLoad) { |
| if (!RunFlag) { | ||
| DesiredMassFlowRate = 0.0; | ||
|
|
||
| } else if (RunFlag && this->InternalFlowControl) { |
There was a problem hiding this comment.
RunFlag is already implied in these else if branches because the preceding if (!RunFlag) (line 1191) has already failed. The four conditions here can be simplified by removing RunFlag &&.
|
|
||
| if (ErrorsFound) { | ||
| ShowFatalError(state, "Preceding sizing errors cause program termination"); | ||
| } |
There was a problem hiding this comment.
ErrorsFound is initialized to false and never updated in this routine, so the final if (ErrorsFound) block is unreachable.
| int SurfDetails = 0; | ||
| bool SurfVert = false; | ||
| bool SurfDet = false; | ||
| bool DXFDone = false; |
There was a problem hiding this comment.
These three are initialized to false.
|
|
||
| General::ScanForReports(state, "Surfaces", DoReport, "Vertices"); | ||
| if (DoReport) { | ||
| if (!SurfVert) { |
There was a problem hiding this comment.
These flags here and below are being checked in places where they are still guaranteed to be false, so the nested if (!flag) branches are redundant.
| General::ScanForReports(state, "Surfaces", DoReport, "VRML", Option1, Option2); | ||
| if (DoReport) { | ||
| bool VRMLDone = false; | ||
| if (!VRMLDone) { |
There was a problem hiding this comment.
VRMLDone is declared locally inside the block and never set to true, so its else branch below is unreachable. the if-else condition can be removed.
| @@ -3464,7 +3464,7 @@ namespace PlantPipingSystemsManager { | |||
| if (CellXIndex <= MinXIndex || CellZIndex <= MinZIndex) { // Ground surface | |||
There was a problem hiding this comment.
If CellXIndex <= MinXIndex || CellZIndex <= MinZIndex is false, then both indices must already be greater than the minimum bounds, so the following else if (CellXIndex >= MinXIndex || CellZIndex >= MinZIndex) (line 3467) is always true. This can be simplified to a plain else.
| auto &AirChillerSet = state.dataRefrigCase->AirChillerSet; | ||
| for (int CoilSetIndex = 1; CoilSetIndex <= state.dataRefrigCase->NumRefrigChillerSets; ++CoilSetIndex) { | ||
| AirChillerSet(CoilSetIndex).CalculateAirChillerSets(state); | ||
| state.dataRefrigCase->AirChillerSet(CoilSetIndex).CalculateAirChillerSets(state); |
There was a problem hiding this comment.
I just removed the one-use AirChillerSet alias and called it directly. That gets rid of the constVariableReference warning and makes it a bit clearer that the element itself is being mutated.
|
|
||
| // Sum up all the case and walk-in loads served by the secondary loop | ||
| if (this->NumCases > 0) { | ||
| auto &RefrigCase = state.dataRefrigCase->RefrigCase; |
There was a problem hiding this comment.
Removed the one-use RefrigCase alias and accessed the element directly. This clears the constVariableReference warning and keeps the mutating call explicit.
| } // CaseNum | ||
| } // NumCases > 0 | ||
| if (this->NumWalkIns > 0) { | ||
| auto &WalkIn = state.dataRefrigCase->WalkIn; |
There was a problem hiding this comment.
Removed the one-use WalkIn alias and accessed the element directly. This clears the constVariableReference warning and keeps the mutating call explicit.
| } | ||
|
|
||
| if (state.dataRefrigCase->NumSimulationWalkIns > 0) { | ||
| auto &WalkIn = state.dataRefrigCase->WalkIn; |
There was a problem hiding this comment.
Removed the one-use WalkIn alias and accessed the element directly. This clears the constVariableReference warning and keeps the mutating call explicit.
|
|
||
| // NOTE: Performed before checking min and max constraints to mimic original implementation | ||
| // in ManagerControllers() | ||
| if (RootFinderData.MinPoint.DefinedFlag && RootFinderData.MaxPoint.DefinedFlag) { |
There was a problem hiding this comment.
RootFinderData.MinPoint.DefinedFlag is already guaranteed by the enclosing condition here,
| if (CheckMinConstraint(state, RootFinderData)) { | ||
| RootFinderData.StatusFlag = RootFinderStatus::OKMin; | ||
| RootFinderData.XCandidate = RootFinderData.MinPoint.X; | ||
| if (CheckMinConstraint(state, RootFinderData)) { |
There was a problem hiding this comment.
so this nested check is redundant and can be removed.
|
|
||
| } else if (is_any_of(NextChar, "+-*/^=<>@|&")) { | ||
| // Parse an operator token | ||
| if (NextChar == '-') { |
There was a problem hiding this comment.
(NextChar == '-') is already guaranteed here
| } | ||
| } | ||
|
|
||
| if ((NumOperands == 5) && (NumTokens >= 6)) { |
There was a problem hiding this comment.
(NumOperands == 5) is already guaranteed here.
| ++NumErrors; | ||
| DivFound = false; | ||
| } else if (OperatorProcessing && (NextChar == '-')) { | ||
| } else if (OperatorProcessing) { |
There was a problem hiding this comment.
so this nested check is redundant and can be removed.
| state.dataRuntimeLang->ErlExpression(ExpressionNum).Operand(5).Number = Token(Pos + 5).Number; | ||
| state.dataRuntimeLang->ErlExpression(ExpressionNum).Operand(5).Expression = Token(Pos + 5).Expression; | ||
| state.dataRuntimeLang->ErlExpression(ExpressionNum).Operand(5).Variable = Token(Pos + 5).Variable; | ||
| if ((NumOperands == 5) && (NumTokens - 6 > 0)) { // too many tokens for this non-binary operator |
There was a problem hiding this comment.
so this nested check is redundant and can be removed.
| // Need to make sure that flows are greater than zero | ||
| if (MassFlowSet >= 0.0) { | ||
| state.dataLoopNodes->Node(NodeNumOut).MassFlowRateSetPoint = MassFlowSet; | ||
| } else if (MassFlowSet < 0.0) { |
There was a problem hiding this comment.
This is redundant since it is the exact opposite of the preceding if (MassFlowSet >= 0.0) in two lines above.
|
|
||
| if (ErrorsFound) { | ||
| ShowFatalError(state, EnergyPlus::format("{}Errors found in input. Preceding condition(s) cause termination.", RoutineName)); | ||
| } |
There was a problem hiding this comment.
ErrorsFound is initialized to false and never updated in this routine, so the final fatal check is unreachable.
| OASysEqSizing(state.dataSize->CurOASysNum).AirFlow = true; | ||
| OASysEqSizing(state.dataSize->CurOASysNum).AirVolFlow = finalSysSizing.DesOutAirVolFlow; | ||
| state.dataSize->OASysEqSizing(state.dataSize->CurOASysNum).AirFlow = true; | ||
| state.dataSize->OASysEqSizing(state.dataSize->CurOASysNum).AirVolFlow = finalSysSizing.DesOutAirVolFlow; |
There was a problem hiding this comment.
Removed the one-use OASysEqSizing alias and used the element directly. This clears the constVariableReference warning and keeps the mutating call explicit.
| TempAbsPlate * (hConvCoefA2C + hRadCoefA2C); | ||
| tempdenom = (hConvCoefC2O + hRadCoefC2O) + (hConvCoefA2C + hRadCoefA2C); | ||
| TempOuterCover = tempnom / tempdenom; | ||
| } else if (NumCovers == 2) { |
There was a problem hiding this comment.
In this NumCovers == 2 branch, the loop index Num can only be 0 or 1. That means once if (Num == 0) is false, Num == 1 is guaranteed, so the else if (Num == 1) can be simplified to a plain else.
| A1eqout = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop); | ||
| A2eqin = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop); | ||
| } else if (Tgap1 < Tgap2) { | ||
| } else { |
There was a problem hiding this comment.
The else if (Tgap1 < Tgap2) is redundant since it is the exact complement of the preceding if (Tgap1 >= Tgap2). This can be simplified to a plain else for the same intended behavior.
| Tup = (alpha1 * Tav1 + beta1 * alpha2 * Tav2) / (1.0 - beta1 * beta2); | ||
| Tdown = alpha2 * Tav2 + beta2 * Tup; | ||
| } else if (Tgap2 >= Tgap1) { | ||
| } else { |
There was a problem hiding this comment.
The else if (Tgap2 >= Tgap1) is redundant since it is the exact complement of the preceding if (Tgap1 > Tgap2). This can be simplified to a plain else for the same intended behavior.
| Temp1 = Tav1 - (H01 / H) * (Tup - Tdown); | ||
| Temp2 = Tav2 - (H02 / H) * (Tdown - Tup); | ||
| } else if (Tgap2 >= Tgap1) { | ||
| } else { |
There was a problem hiding this comment.
The else if (Tgap2 >= Tgap1) is redundant since it is the exact complement of the preceding if (Tgap1 > Tgap2). This can be simplified to a plain else for the same intended behavior.
| qv1 = -dens1 * cp1 * speed1 * s1 * L * (Tdown - Tup) / (H * L); | ||
| qv2 = -dens2 * cp2 * speed2 * s2 * L * (Tup - Tdown) / (H * L); | ||
| } else if (Tgap2 < Tgap1) { | ||
| } else { |
There was a problem hiding this comment.
The else if (Tgap2 < Tgap1) is redundant since it is the exact complement of the preceding if (Tgap2 >= Tgap1). This can be simplified to a plain else for the same intended behavior.
| A1eqin = Abot + 0.5 * Atop * (Al + Ar + Ah) / (Abot + Atop); | ||
| A1eqout = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop); | ||
| } else if (Tgap <= Tenv) { | ||
| } else { |
There was a problem hiding this comment.
The else if (Tgap <= Tenv) is redundant since it is the exact complement of the preceding if (Tgap > Tenv). This can be simplified to a plain else for the same intended behavior.
| ZoneEqSizing(state.dataSize->CurZoneEqNum).CoolingAirVolFlow = state.dataSize->DataNonZoneNonAirloopValue; | ||
| state.dataSize->ZoneEqSizing(state.dataSize->CurZoneEqNum).CoolingAirFlow = true; | ||
| state.dataSize->ZoneEqSizing(state.dataSize->CurZoneEqNum).CoolingAirVolFlow = state.dataSize->DataNonZoneNonAirloopValue; | ||
| } |
There was a problem hiding this comment.
Removed the one-use ZoneEqSizing alias and used the element directly. This clears the constVariableReference warning and keeps the mutating call explicit.
There was a problem hiding this comment.
@dareumnam here's my thoughts on this.
Never use a class reference:
auto &ZoneEqSizing = state.dataSize->ZoneEqSizing;
and instead use an object reference:
auto &ZoneEqSizing = state.dataSize->ZoneEqSizing(state.dataSize->CurZoneEqNum);
but don't create the reference unless there are more than 2 usages (that's just my personal preference).
So in this case I agree with this change. You could have used the object reference here and that would still be OK because it was used twice. Creating a reference to use it one time just adds more code than is needed.
Your code change here seems fine to me.
| LOK = true; | ||
| DOK = true; | ||
| BOK = true; | ||
| } |
There was a problem hiding this comment.
LOK, DOK, and BOK are assigned throughout this routine but never actually checked afterward, so cppcheck looks right here. It seems these calls are being made for their side effects on L.LWP_EL / L.SWP_EL, while the bool return values are currently unused. If the return status is not needed, the locals can probably be removed. Otherwise this may be missing an error check.
There was a problem hiding this comment.
I don't want to add to the effort here but if these locals are not needed then do these 12 functions even need to return a bool? e.g., bool PD_LWP{ .. return PD_LWP}; Maybe the developer used these bools for debugging and never removed them?
Pull request overview
Description of the purpose of this PR
Pull Request Author
Reviewer