Resolve cppcheck unreadVariable warnings#11411
Conversation
| { | ||
|
|
||
| std::array<Real64, DataConvergParams::ConvergLogStackDepth> tmpRealARR = {}; | ||
| std::array<Real64, DataConvergParams::ConvergLogStackDepth> tmpRealARR; |
There was a problem hiding this comment.
Remove the zero-initialization of tmpRealARR. It is always overwritten before being read, so the initialization was redundant and triggered a cppcheck warning.
| } else if (field_value.get<std::string>().empty()) { | ||
| isDefaulted = findDefault(defaultValue, schema_field_obj); | ||
| if (isDefaulted) { | ||
| if (findDefault(defaultValue, schema_field_obj)) { |
There was a problem hiding this comment.
Remove the temporary isDefaulted variable and use findDefault() directly in the condition to remove cppcheck error as it was redundant and only stored an intermediate result.
| auto epwFile = state.files.inputWeatherFilePath.open(state, "CalcThermalComfortAdaptiveASH55"); | ||
| for (i = 1; i <= 8; ++i) { // Headers | ||
| epwLine = epwFile.readLine().data; | ||
| epwFile.readLine(); |
There was a problem hiding this comment.
I updated the code to call readLine() without assigning the result to epwLine, since the code stored each skipped line into epwLine and immediately overwrote it in the next iteration without ever reading it. This removes the dead assignments flagged by cppcheck and makes the intent clearer, with no change in behavior. I made the same change below.
| ExpandComplexState(state, iSurf, state.dataSurface->Surface(iSurf).Construction); | ||
| CurrentCFSState = state.dataSurface->SurfaceWindow(iSurf).ComplexFen.NumStates; | ||
| state.dataSurface->SurfaceWindow(iSurf).ComplexFen.CurrentState = CurrentCFSState; | ||
| state.dataSurface->SurfaceWindow(iSurf).ComplexFen.CurrentState = state.dataSurface->SurfaceWindow(iSurf).ComplexFen.NumStates; |
There was a problem hiding this comment.
Drop the redundant CurrentCFSState local and write directly to ComplexFen.CurrentState. The cached value wasn’t needed and cppcheck flagged it as unreadVariable. No behavior change.
|
|
||
| ngllayer = state.dataConstruction->Construct(ConstrNum).TotGlassLayers; | ||
| nglface = 2 * ngllayer; | ||
| nglfacep = nglface; |
There was a problem hiding this comment.
Dropped this initialization as it gets overwritten before being read, so cppcheck flags it as unreadVariable. No behavior change.
| A(3, 3) = 1.0; | ||
| A(4, 3) = -1.0 * rhodb; | ||
| A(3, 4) = -1.0 * rhom; | ||
| // cppcheck-suppress unreadVariable |
There was a problem hiding this comment.
cppcheck false positive: this routine fills A as an output matrix, so the last assignment A(4,4)=1.0 isn’t unused in practice. Added a local suppress to keep the intent clear.
| } | ||
| } | ||
| } | ||
| CFSLAYERFlag = LOK && DOK && BOK; |
There was a problem hiding this comment.
Dropped unused CFSLAYERFlag as it was computed but never read.
| TGapNew(1) = | ||
| TAve(1) - (TAve(1) - TAve(2)) * (GapHeightChar(1) / GapHeight) * (1 - EpsChar(1)) * (1 - EpsChar(2)) / (1 - EpsChar(1) * EpsChar(2)); | ||
|
|
||
| // cppcheck-suppress unreadVariable |
There was a problem hiding this comment.
cppcheck false positive: TGapNew is an output array; TGapNew(2) is set here for the caller.
| Real64 BlindIRreflBack = G(2) * (1.0 - fEdge) + fEdge * ri; // Blind back IR reflectance | ||
|
|
||
| // Back IR emissivity | ||
| // cppcheck-suppress unreadVariable |
There was a problem hiding this comment.
cppcheck false positive: p is an output array and p(15) is set here for the caller.
|
Pull request overview
Description of the purpose of this PR
Pull Request Author
Reviewer