Skip to content

Commit

Permalink
Merge pull request #10614 from rouault/coverity_1559325
Browse files Browse the repository at this point in the history
Fix Coverity warnings
  • Loading branch information
rouault authored Aug 25, 2024
2 parents c05292d + 7dce690 commit 2c50449
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions gcore/gdalrasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ CPLErr GDALRasterBand::ReadRaster(T *pData, size_t nArrayEltCount,
const bool bCallLeaveReadWrite =
CPL_TO_BOOL(pThis->EnterReadWrite(GF_Read));
CPLErr eErr;
// coverity[identical_branches]
if (bForceCachedIO)
eErr = pThis->GDALRasterBand::IRasterIO(
GF_Read, nXOff, nYOff, nXSize, nYSize, pData,
Expand Down Expand Up @@ -938,6 +939,7 @@ CPLErr GDALRasterBand::ReadRaster(std::vector<T> &vData, double dfXOff,
CPL_TO_BOOL(pThis->EnterReadWrite(GF_Read));

CPLErr eErr;
// coverity[identical_branches]
if (bForceCachedIO)
eErr = pThis->GDALRasterBand::IRasterIO(
GF_Read, nXOff, nYOff, nXSize, nYSize, vData.data(),
Expand Down
27 changes: 16 additions & 11 deletions ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <algorithm>
#include <map>
#include <tuple>

#include "ogr_parquet.h"
#include "ogrparquetdrivercore.h"
Expand Down Expand Up @@ -71,16 +72,17 @@ static GDALDataset *OpenFromDatasetFactory(
/* GetFileSystem() */
/************************************************************************/

static std::shared_ptr<arrow::fs::FileSystem>
static std::tuple<std::shared_ptr<arrow::fs::FileSystem>, std::string>
GetFileSystem(std::string &osBasePathInOut,
const std::string &osQueryParameters, std::string &osFSFilename)
const std::string &osQueryParameters)
{
// Instantiate file system:
// - VSIArrowFileSystem implementation for /vsi files
// - base implementation for local files (if OGR_PARQUET_USE_VSI set to NO)
std::shared_ptr<arrow::fs::FileSystem> fs;
const bool bIsVSI = STARTS_WITH(osBasePathInOut.c_str(), "/vsi");
VSIStatBufL sStat;
std::string osFSFilename;
if ((bIsVSI ||
CPLTestBool(CPLGetConfigOption("OGR_PARQUET_USE_VSI", "YES"))) &&
VSIStatL(osBasePathInOut.c_str(), &sStat) == 0)
Expand All @@ -97,14 +99,14 @@ GetFileSystem(std::string &osBasePathInOut,
{
char *pszCurDir = CPLGetCurrentDir();
if (pszCurDir == nullptr)
return nullptr;
return {nullptr, osFSFilename};
osPath = CPLFormFilename(pszCurDir, osPath.c_str(), nullptr);
CPLFree(pszCurDir);
}
PARQUET_ASSIGN_OR_THROW(
fs, arrow::fs::FileSystemFromUriOrPath(osPath, &osFSFilename));
}
return fs;
return {fs, osFSFilename};
}

/************************************************************************/
Expand All @@ -116,18 +118,19 @@ static GDALDataset *OpenParquetDatasetWithMetadata(
const std::string &osQueryParameters, CSLConstList papszOpenOptions)
{
std::string osBasePath(osBasePathIn);
std::string osFSFilename;
auto fs = GetFileSystem(osBasePath, osQueryParameters, osFSFilename);
const auto &[fs, osFSFilename] =
GetFileSystem(osBasePath, osQueryParameters);

arrow::dataset::ParquetFactoryOptions options;
auto partitioningFactory = arrow::dataset::HivePartitioning::MakeFactory();
options.partitioning =
arrow::dataset::PartitioningOrFactory(std::move(partitioningFactory));

std::shared_ptr<arrow::dataset::DatasetFactory> factory;
// coverity[copy_constructor_call]
PARQUET_ASSIGN_OR_THROW(
factory, arrow::dataset::ParquetDatasetFactory::Make(
osFSFilename + '/' + pszMetadataFile, std::move(fs),
osFSFilename + '/' + pszMetadataFile, fs,
std::make_shared<arrow::dataset::ParquetFileFormat>(),
std::move(options)));

Expand All @@ -144,18 +147,19 @@ OpenParquetDatasetWithoutMetadata(const std::string &osBasePathIn,
CSLConstList papszOpenOptions)
{
std::string osBasePath(osBasePathIn);
std::string osFSFilename;
auto fs = GetFileSystem(osBasePath, osQueryParameters, osFSFilename);
const auto &[fs, osFSFilename] =
GetFileSystem(osBasePath, osQueryParameters);

arrow::dataset::FileSystemFactoryOptions options;
std::shared_ptr<arrow::dataset::DatasetFactory> factory;

const auto fileInfo = fs->GetFileInfo(osFSFilename);
if (fileInfo->IsFile())
{
// coverity[copy_constructor_call]
PARQUET_ASSIGN_OR_THROW(
factory, arrow::dataset::FileSystemDatasetFactory::Make(
std::move(fs), {osFSFilename},
fs, {std::move(osFSFilename)},
std::make_shared<arrow::dataset::ParquetFileFormat>(),
std::move(options)));
}
Expand All @@ -170,9 +174,10 @@ OpenParquetDatasetWithoutMetadata(const std::string &osBasePathIn,
selector.base_dir = std::move(osFSFilename);
selector.recursive = true;

// coverity[copy_constructor_call]
PARQUET_ASSIGN_OR_THROW(
factory, arrow::dataset::FileSystemDatasetFactory::Make(
std::move(fs), std::move(selector),
fs, std::move(selector),
std::make_shared<arrow::dataset::ParquetFileFormat>(),
std::move(options)));
}
Expand Down

0 comments on commit 2c50449

Please sign in to comment.