Skip to content
Draft
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions alg/gdalwarpoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,18 +723,33 @@ GDALWarpOperation::Initialize(const GDALWarpOptions *psNewOptions,
}
}

if (eErr == CE_None && psOptions->hDstDS &&
CPLTestBool(CSLFetchNameValueDef(psOptions->papszWarpOptions,
"RESET_DEST_PIXELS", "NO")))
if (eErr == CE_None && psOptions->hDstDS)
{
for (int i = 0; eErr == CE_None && i < psOptions->nBandCount; ++i)
const auto oResetDestPixels =
cpl::strict_parse<bool>(CSLFetchNameValueDef(
psOptions->papszWarpOptions, "RESET_DEST_PIXELS", "NO"));

if (!oResetDestPixels.has_value())
{
eErr = GDALFillRaster(
GDALGetRasterBand(psOptions->hDstDS, psOptions->panDstBands[i]),
psOptions->padfDstNoDataReal ? psOptions->padfDstNoDataReal[i]
: 0.0,
psOptions->padfDstNoDataImag ? psOptions->padfDstNoDataImag[i]
: 0.0);
CPLError(CE_Failure, CPLE_IllegalArg,
"Invalid value of RESET_DEST_PIXELS");
return CE_Failure;
}

if (oResetDestPixels.value())
{
for (int i = 0; eErr == CE_None && i < psOptions->nBandCount; ++i)
{
eErr =
GDALFillRaster(GDALGetRasterBand(psOptions->hDstDS,
psOptions->panDstBands[i]),
psOptions->padfDstNoDataReal
? psOptions->padfDstNoDataReal[i]
: 0.0,
psOptions->padfDstNoDataImag
? psOptions->padfDstNoDataImag[i]
: 0.0);
}
}
}

Expand Down Expand Up @@ -3283,7 +3298,17 @@ CPLErr GDALWarpOperation::ComputeSourceWindow(
if (const char *pszSourceExtra =
CSLFetchNameValue(psOptions->papszWarpOptions, "SOURCE_EXTRA"))
{
const int nSrcExtra = atoi(pszSourceExtra);
int nSrcExtra = cpl::strict_parse<int>(pszSourceExtra).value_or(-1);

if (nSrcExtra < 0)
{
// no point raising CE_Failure because it will get converted into
// a warning at an outer scope
CPLError(CE_Warning, CPLE_IllegalArg,
"SOURCE_EXTRA must be a positive integer or zero.");
nSrcExtra = 0;
}

nXRadius += nSrcExtra;
nYRadius += nSrcExtra;
}
Expand Down
12 changes: 6 additions & 6 deletions apps/gdal_rasterize_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,16 +678,16 @@ static CPLErr ProcessLayer(OGRLayerH hSrcLayer, bool bSRSIsSet,
{
const char *pszAttribute =
OGR_F_GetFieldAsString(hFeat, iBurnField);
char *end;
dfBurnValue = CPLStrtod(pszAttribute, &end);

while (isspace(*end) && *end != '\0')
if (auto parsed =
cpl::strict_parse<double>(pszAttribute);
parsed.has_value())
{
end++;
dfBurnValue = parsed.value();
}

if (*end != '\0')
else
{
dfBurnValue = 0;
CPLErrorOnce(
CE_Warning, CPLE_AppDefined,
"Failed to parse attribute value %s of feature "
Expand Down
9 changes: 6 additions & 3 deletions apps/gdalalg_raster_calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,12 @@ CreateDerivedBandXML(const char *pszVRTFilename, CPLXMLNode *root, int nXOut,
}
else if (noDataText != "none")
{
char *end;
dstNoData = CPLStrtod(noDataText.c_str(), &end);
if (end != noDataText.c_str() + noDataText.size())
if (auto parsed = cpl::strict_parse<double>(noDataText);
parsed.has_value())
{
dstNoData = parsed.value();
}
else
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid NoData value: %s", noDataText.c_str());
Expand Down
25 changes: 5 additions & 20 deletions apps/gdalalg_raster_resize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,13 @@ GDALRasterResizeAlgorithm::GDALRasterResizeAlgorithm(bool standaloneStep)
{
for (const auto &s : m_size)
{
char *endptr = nullptr;
const double val = CPLStrtod(s.c_str(), &endptr);
bool ok = false;
if (endptr == s.c_str() + s.size())
auto trimmed = cpl::trim(s);
if (!trimmed.empty() && trimmed.back() == '%')
{
if (val >= 0 && val <= INT_MAX &&
static_cast<int>(val) == val)
{
ok = true;
}
trimmed = trimmed.substr(0, trimmed.size() - 1);
}
else if (endptr && ((endptr[0] == ' ' && endptr[1] == '%' &&
endptr + 2 == s.c_str() + s.size()) ||
(endptr[0] == '%' &&
endptr + 1 == s.c_str() + s.size())))
{
if (val >= 0)
{
ok = true;
}
}
if (!ok)

if (cpl::strict_parse<int>(trimmed).value_or(-1) < 0)
{
ReportError(CE_Failure, CPLE_IllegalArg,
"Invalid size value: %s'", s.c_str());
Expand Down
21 changes: 17 additions & 4 deletions apps/ogr2ogr_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8580,10 +8580,23 @@ GDALVectorTranslateOptions *GDALVectorTranslateOptionsNew(
psOptions->asGCPs.resize(psOptions->asGCPs.size() + 1);
auto &sGCP = psOptions->asGCPs.back();

sGCP.Pixel() = CPLAtof(papszArgv[++i]);
sGCP.Line() = CPLAtof(papszArgv[++i]);
sGCP.X() = CPLAtof(papszArgv[++i]);
sGCP.Y() = CPLAtof(papszArgv[++i]);
const auto oPixel = cpl::strict_parse<double>(papszArgv[++i]);
const auto oLine = cpl::strict_parse<double>(papszArgv[++i]);
const auto oX = cpl::strict_parse<double>(papszArgv[++i]);
const auto oY = cpl::strict_parse<double>(papszArgv[++i]);

if (!oPixel.has_value() || !oLine.has_value() || !oX.has_value() ||
!oY.has_value())
{
CPLError(CE_Failure, CPLE_IllegalArg, "Invalid -gcp value");
return nullptr;
}

sGCP.Pixel() = oPixel.value();
sGCP.Line() = oLine.value();
sGCP.X() = oX.value();
sGCP.Y() = oY.value();

if (papszArgv[i + 1] != nullptr &&
(CPLStrtod(papszArgv[i + 1], &endptr) != 0.0 ||
papszArgv[i + 1][0] == '0'))
Expand Down
Loading
Loading