Skip to content

Commit d7ec92c

Browse files
committed
Coverity Scan warning fixes
1 parent cc5dfea commit d7ec92c

File tree

4 files changed

+54
-54
lines changed

4 files changed

+54
-54
lines changed

apps/gdalalg_abstract_pipeline.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ bool GDALAbstractPipelineAlgorithm::ParseCommandLineArguments(
422422
}
423423
else
424424
{
425-
nestedPipelineArgs.push_back(arg);
425+
nestedPipelineArgs.push_back(std::move(arg));
426426
continue;
427427
}
428428
}
@@ -437,7 +437,7 @@ bool GDALAbstractPipelineAlgorithm::ParseCommandLineArguments(
437437
return false;
438438
}
439439
}
440-
nestedPipelineArgs.push_back(arg);
440+
nestedPipelineArgs.push_back(std::move(arg));
441441
continue;
442442
}
443443
}
@@ -510,7 +510,7 @@ bool GDALAbstractPipelineAlgorithm::ParseCommandLineArguments(
510510
#endif
511511
else if (!curStep.alg)
512512
{
513-
std::string algName = arg;
513+
std::string algName = std::move(arg);
514514
#ifdef GDAL_PIPELINE_PROJ_NOSTALGIA
515515
if (!algName.empty() && algName[0] == '+')
516516
algName = algName.substr(1);
@@ -545,7 +545,7 @@ bool GDALAbstractPipelineAlgorithm::ParseCommandLineArguments(
545545
continue;
546546
}
547547
#endif
548-
curStep.args.push_back(arg);
548+
curStep.args.push_back(std::move(arg));
549549
}
550550
}
551551

frmts/hfa/hfaopen.cpp

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,46 +3746,48 @@ CPLErr HFARenameReferences(HFAHandle hHFA, const char *pszNewBase,
37463746

37473747
// Collect all the existing names.
37483748
const int nNameCount = poRRDNL->GetFieldCount("nameList");
3749-
3750-
CPLString osAlgorithm = poRRDNL->GetStringField("algorithm.string");
3751-
for (int i = 0; i < nNameCount; i++)
3749+
if (nNameCount >= 0)
37523750
{
3753-
CPLString osFN;
3754-
osFN.Printf("nameList[%d].string", i);
3755-
aosNL.push_back(poRRDNL->GetStringField(osFN));
3756-
}
3751+
CPLString osAlgorithm = poRRDNL->GetStringField("algorithm.string");
3752+
for (int i = 0; i < nNameCount; i++)
3753+
{
3754+
CPLString osFN;
3755+
osFN.Printf("nameList[%d].string", i);
3756+
aosNL.push_back(poRRDNL->GetStringField(osFN));
3757+
}
37573758

3758-
// Adjust the names to the new form.
3759-
for (int i = 0; i < nNameCount; i++)
3760-
{
3761-
if (strncmp(aosNL[i], pszOldBase, strlen(pszOldBase)) == 0)
3759+
// Adjust the names to the new form.
3760+
for (int i = 0; i < nNameCount; i++)
37623761
{
3763-
std::string osNew = pszNewBase;
3764-
osNew += aosNL[i].c_str() + strlen(pszOldBase);
3765-
aosNL[i] = std::move(osNew);
3762+
if (strncmp(aosNL[i], pszOldBase, strlen(pszOldBase)) == 0)
3763+
{
3764+
std::string osNew = pszNewBase;
3765+
osNew += aosNL[i].c_str() + strlen(pszOldBase);
3766+
aosNL[i] = std::move(osNew);
3767+
}
37663768
}
3767-
}
37683769

3769-
// Try to make sure the RRDNamesList is big enough to hold the
3770-
// adjusted name list.
3771-
if (strlen(pszNewBase) > strlen(pszOldBase))
3772-
{
3773-
CPLDebug("HFA", "Growing RRDNamesList to hold new names");
3774-
poRRDNL->MakeData(static_cast<int>(
3775-
poRRDNL->GetDataSize() +
3776-
nNameCount * (strlen(pszNewBase) - strlen(pszOldBase))));
3777-
}
3770+
// Try to make sure the RRDNamesList is big enough to hold the
3771+
// adjusted name list.
3772+
if (strlen(pszNewBase) > strlen(pszOldBase))
3773+
{
3774+
CPLDebug("HFA", "Growing RRDNamesList to hold new names");
3775+
poRRDNL->MakeData(static_cast<int>(
3776+
poRRDNL->GetDataSize() +
3777+
nNameCount * (strlen(pszNewBase) - strlen(pszOldBase))));
3778+
}
37783779

3779-
// Initialize the whole thing to zeros for a clean start.
3780-
memset(poRRDNL->GetData(), 0, poRRDNL->GetDataSize());
3780+
// Initialize the whole thing to zeros for a clean start.
3781+
memset(poRRDNL->GetData(), 0, poRRDNL->GetDataSize());
37813782

3782-
// Write the updates back to the file.
3783-
poRRDNL->SetStringField("algorithm.string", osAlgorithm);
3784-
for (int i = 0; i < nNameCount; i++)
3785-
{
3786-
CPLString osFN;
3787-
osFN.Printf("nameList[%d].string", i);
3788-
poRRDNL->SetStringField(osFN, aosNL[i]);
3783+
// Write the updates back to the file.
3784+
poRRDNL->SetStringField("algorithm.string", osAlgorithm);
3785+
for (int i = 0; i < nNameCount; i++)
3786+
{
3787+
CPLString osFN;
3788+
osFN.Printf("nameList[%d].string", i);
3789+
poRRDNL->SetStringField(osFN, aosNL[i]);
3790+
}
37893791
}
37903792
}
37913793

frmts/nitf/nitffile.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,7 +2745,6 @@ static char **NITFGenericMetadataReadTREInternal(
27452745
}
27462746
if (pszName != nullptr && nLength > 0)
27472747
{
2748-
char *pszMDItemName;
27492748
char **papszTmp = nullptr;
27502749
char *pszValue = nullptr;
27512750

@@ -2761,8 +2760,8 @@ static char **NITFGenericMetadataReadTREInternal(
27612760
break;
27622761
}
27632762

2764-
pszMDItemName =
2765-
CPLStrdup(CPLSPrintf("%s%s", pszMDPrefix, pszName));
2763+
const std::string osMDItemName =
2764+
CPLSPrintf("%s%s", pszMDPrefix, pszName);
27662765

27672766
if (strcmp(pszType, "IEEE754_Float32_BigEndian") == 0)
27682767
{
@@ -2774,8 +2773,8 @@ static char **NITFGenericMetadataReadTREInternal(
27742773
CPL_MSBPTR32(&f);
27752774
pszValue = static_cast<char *>(CPLMalloc(nBufferSize));
27762775
CPLsnprintf(pszValue, nBufferSize, "%f", f);
2777-
papszTmp =
2778-
CSLSetNameValue(papszTmp, pszMDItemName, pszValue);
2776+
papszTmp = CSLSetNameValue(
2777+
papszTmp, osMDItemName.c_str(), pszValue);
27792778
}
27802779
else
27812780
{
@@ -2798,8 +2797,8 @@ static char **NITFGenericMetadataReadTREInternal(
27982797
const int nBufferSize = 24;
27992798
pszValue = static_cast<char *>(CPLMalloc(nBufferSize));
28002799
CPLsnprintf(pszValue, nBufferSize, "%.17g", df);
2801-
papszTmp =
2802-
CSLSetNameValue(papszTmp, pszMDItemName, pszValue);
2800+
papszTmp = CSLSetNameValue(
2801+
papszTmp, osMDItemName.c_str(), pszValue);
28032802
}
28042803
else
28052804
{
@@ -2832,8 +2831,8 @@ static char **NITFGenericMetadataReadTREInternal(
28322831
pszValue = static_cast<char *>(CPLMalloc(nBufferSize));
28332832
CPLsnprintf(pszValue, nBufferSize, CPL_FRMT_GUIB,
28342833
static_cast<GUIntBig>(nVal));
2835-
papszTmp =
2836-
CSLSetNameValue(papszTmp, pszMDItemName, pszValue);
2834+
papszTmp = CSLSetNameValue(
2835+
papszTmp, osMDItemName.c_str(), pszValue);
28372836
}
28382837
else
28392838
{
@@ -2849,16 +2848,16 @@ static char **NITFGenericMetadataReadTREInternal(
28492848
else if (strcmp(pszType, "ISO8859-1") == 0)
28502849
{
28512850
NITFExtractMetadata(&papszTmp, pachTRE, *pnTreOffset,
2852-
nLength, pszMDItemName);
2851+
nLength, osMDItemName.c_str());
28532852

2854-
pszValue =
2855-
CPLStrdup(CSLFetchNameValue(papszTmp, pszMDItemName));
2853+
pszValue = CPLStrdup(
2854+
CSLFetchNameValue(papszTmp, osMDItemName.c_str()));
28562855
}
28572856
else
28582857
{
2859-
NITFExtractAndRecodeMetadata(&papszTmp, pachTRE,
2860-
*pnTreOffset, nLength,
2861-
pszMDItemName, CPL_ENC_UTF8);
2858+
NITFExtractAndRecodeMetadata(
2859+
&papszTmp, pachTRE, *pnTreOffset, nLength,
2860+
osMDItemName.c_str(), CPL_ENC_UTF8);
28622861

28632862
pszValue = CPLStrdup(strchr(papszTmp[0], '=') + 1);
28642863
}
@@ -2987,7 +2986,6 @@ static char **NITFGenericMetadataReadTREInternal(
29872986
}
29882987
}
29892988

2990-
CPLFree(pszMDItemName);
29912989
CPLFree(pszValue);
29922990

29932991
*pnTreOffset += nLength;

gcore/gdalpamdataset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ GDALPamDataset::GDALPamDataset()
148148
GDALPamDataset::~GDALPamDataset()
149149

150150
{
151-
GDALPamDataset::Close();
151+
CPL_IGNORE_RET_VAL(GDALPamDataset::Close());
152152

153153
PamClear();
154154
}

0 commit comments

Comments
 (0)