From 24e0324c60b76cce60549052c52cd1240ffc8efc Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Tue, 18 Feb 2025 16:02:41 +0100 Subject: [PATCH] CDIReader: Fix multiple issues found on Windows --- Plugins/CDIReader/Reader/cdi_tools.cxx | 3 ++- Plugins/CDIReader/Reader/cdi_tools.h | 3 ++- Plugins/CDIReader/Reader/vtkCDIReader.cxx | 18 ++++++------------ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Plugins/CDIReader/Reader/cdi_tools.cxx b/Plugins/CDIReader/Reader/cdi_tools.cxx index b6cf3477de7..51924e66f6d 100644 --- a/Plugins/CDIReader/Reader/cdi_tools.cxx +++ b/Plugins/CDIReader/Reader/cdi_tools.cxx @@ -31,12 +31,13 @@ std::string get_att_str(const std::string& filename, const std::string& var, con status = nc_inq_attlen(ncFD, varId, att.c_str(), &len); if (status != NC_NOERR) return result; - char buffer[len + 1]; + char* buffer = new char[len + 1]; status = nc_get_att_text(ncFD, varId, att.c_str(), buffer); if (status != NC_NOERR) return result; buffer[len] = 0; result = buffer; + delete[] buffer; return result; } diff --git a/Plugins/CDIReader/Reader/cdi_tools.h b/Plugins/CDIReader/Reader/cdi_tools.h index c113a27b627..018823bae7d 100644 --- a/Plugins/CDIReader/Reader/cdi_tools.h +++ b/Plugins/CDIReader/Reader/cdi_tools.h @@ -89,7 +89,7 @@ template void cdi_get_part_struct(CDIVar* cdiVar, int start, size_t size, T* buffer, int nlevels) { const size_t gridsize = cdiVar->GridSize; - T fullbuff[gridsize * nlevels]; + T* fullbuff = new T[gridsize * nlevels]; cdi_get_full(cdiVar, fullbuff, nlevels); for (size_t lev = 0; lev < nlevels; lev++) { @@ -98,6 +98,7 @@ void cdi_get_part_struct(CDIVar* cdiVar, int start, size_t size, T* buffer, int buffer[i + lev * size] = fullbuff[(lev * gridsize) + start + i]; } } + delete[] fullbuff; } template diff --git a/Plugins/CDIReader/Reader/vtkCDIReader.cxx b/Plugins/CDIReader/Reader/vtkCDIReader.cxx index 878f7bc0253..226c23ba7f5 100644 --- a/Plugins/CDIReader/Reader/vtkCDIReader.cxx +++ b/Plugins/CDIReader/Reader/vtkCDIReader.cxx @@ -884,7 +884,7 @@ int vtkCDIReader::GetDims() { this->NumberOfCells = static_cast(this->Internals->Grids.at(GridID).Size); - if (this->NumberOfPoints and this->NumberOfPoints != this->NumberOfCells) + if (this->NumberOfPoints && this->NumberOfPoints != this->NumberOfCells) { vtkDebugMacro("GetDims: Changing number of points from " << this->NumberOfPoints << " to " << this->NumberOfCells); @@ -951,9 +951,7 @@ int vtkCDIReader::ReadHorizontalGridData() if (nv >= 3) // ((nv == 3 || nv == 4)) // && gridInqType(gridID_l) == GRID_UNSTRUCTURED) { - Grid grid{ - .GridID = gridID_l, .Size = static_cast(gridInqSize(gridID_l)), .PointsPerCell = nv - }; + Grid grid{ gridID_l, static_cast(gridInqSize(gridID_l)), nv }; this->Internals->Grids.push_back(grid); } } @@ -1064,7 +1062,7 @@ int vtkCDIReader::GetVars() { vtkDebugMacro("Skipping " << aVar.Name << " as it has the wrong GridSize " << aVar.GridSize << " != " << this->NumberOfCells); - if (this->NumberOfPoints and this->NumberOfPoints != aVar.GridSize) + if (this->NumberOfPoints && this->NumberOfPoints != aVar.GridSize) { vtkWarningMacro("Not adding " << aVar.Name << " as point var, as it's size " << aVar.GridSize @@ -1455,7 +1453,7 @@ int vtkCDIReader::ConstructGridGeometry() vtkDebugMacro("Removed duplicates for clon/clat"); this->NumberLocalCells = new_cells[0] / this->PointsPerCell; this->NumberLocalPoints = new_cells[1]; - if (this->NumberOfPoints and this->NumberOfPoints != new_cells[1]) + if (this->NumberOfPoints && this->NumberOfPoints != new_cells[1]) { vtkDebugMacro("ConstructGridGeometry: Changing number of points from " << this->NumberOfPoints << " to " << new_cells[1]); @@ -3156,12 +3154,8 @@ int vtkCDIReader::FillGridDimensions() << i << '\t' << j << "\t" << gridID_l << '\t' << zaxisID_l << "\t" << dimEncoding << " - has hits.\n"); - Dimset ds{ .DimsetID = counter, - .GridID = -1, - .ZAxisID = zaxisID_l, - .GridSize = static_cast(gridInqSize(gridID_l)), - .NLevel = zaxisInqSize(zaxisID_l), - .label = dimEncoding }; + Dimset ds{ counter, -1, zaxisID_l, static_cast(gridInqSize(gridID_l)), + zaxisInqSize(zaxisID_l), dimEncoding }; this->Internals->DimensionSets[dimEncoding] = ds; counter++; } -- GitLab