From 475c0bf07c7265b8ef987b3000740d71a3ca6d8e Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Fri, 29 Jan 2021 23:20:02 +0100 Subject: [PATCH] [App/IO] Raster; Avoid use after move. Use vector. Using std::vector local variable avoids possible use after move: access to header.n_cols and n_rows in the same line as std::move(header). --- Applications/FileIO/AsciiRasterInterface.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Applications/FileIO/AsciiRasterInterface.cpp b/Applications/FileIO/AsciiRasterInterface.cpp index 107c417c90f..6c426a54bb0 100644 --- a/Applications/FileIO/AsciiRasterInterface.cpp +++ b/Applications/FileIO/AsciiRasterInterface.cpp @@ -51,7 +51,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn // header information GeoLib::RasterHeader header; if (readASCHeader(in, header)) { - auto* values = new double[header.n_cols * header.n_rows]; + std::vector<double> values(header.n_cols * header.n_rows); std::string s; // read the data into the double-array for (std::size_t j(0); j < header.n_rows; ++j) { @@ -64,8 +64,8 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn } in.close(); GeoLib::Raster* raster(new GeoLib::Raster( - std::move(header), values, values + header.n_cols * header.n_rows)); - delete [] values; + std::move(header), values.data(), values.data() + values.size())); + return raster; } WARN("Raster::getRasterFromASCFile(): Could not read header of file {:s}", @@ -172,7 +172,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& if (readSurferHeader(in, header, min, max)) { const double no_data_val (min-1); - auto* values = new double[header.n_cols * header.n_rows]; + std::vector<double> values(header.n_cols * header.n_rows); std::string s; // read the data into the double-array for (std::size_t j(0); j < header.n_rows; ++j) @@ -188,8 +188,8 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& } in.close(); GeoLib::Raster* raster(new GeoLib::Raster( - std::move(header), values, values + header.n_cols * header.n_rows)); - delete [] values; + std::move(header), values.data(), values.data() + values.size())); + return raster; } ERR("Raster::getRasterFromASCFile() - could not read header of file {:s}", -- GitLab