Skip to content

Commit a14ef1f

Browse files
committed
Fix/workaround cppcheck warnings about always true/false conditions
1 parent 3d0741a commit a14ef1f

File tree

8 files changed

+25
-24
lines changed

8 files changed

+25
-24
lines changed

frmts/raw/cpgdataset.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,14 +1295,14 @@ CPLErr SIRC_QSLCRasterBand::IReadBlock(CPL_UNUSED int nBlockXOff,
12951295
/* Initialize our power table if this is our first time through. */
12961296
/* -------------------------------------------------------------------- */
12971297
static float afPowTable[256];
1298-
[[maybe_unused]] static bool bPowTableInitialized = []()
1298+
[[maybe_unused]] static bool bPowTableInitialized = [](bool ret)
12991299
{
13001300
for (int i = 0; i < 256; i++)
13011301
{
13021302
afPowTable[i] = static_cast<float>(pow(2.0, i - 128));
13031303
}
1304-
return true;
1305-
}();
1304+
return ret;
1305+
}(true);
13061306

13071307
/* -------------------------------------------------------------------- */
13081308
/* Copy the desired band out based on the size of the type, and */

frmts/zarr/crc32c.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ static void crc32c_init_hw(void) {
163163
/* Compute CRC-32C using the Intel hardware instruction. */
164164
static uint32_t crc32c_hw(uint32_t crc, void const *buf, size_t len) {
165165
/* populate shift tables the first time through */
166-
static bool bInit = []()
166+
static bool bInit = [](bool ret)
167167
{
168168
crc32c_init_hw();
169-
return true;
170-
}();
169+
return ret;
170+
}(true);
171171
(void)bInit;
172172

173173
/* pre-process the crc */
@@ -273,7 +273,7 @@ static uint32_t crc32c_hw(uint32_t crc, void const *buf, size_t len) {
273273
version. Otherwise, use the software version. */
274274
void crc32c_init(void) {
275275

276-
static const bool bInit = [](){
276+
static const bool bInit = [](bool ret){
277277
int sse42;
278278

279279
SSE42(sse42);
@@ -282,8 +282,8 @@ void crc32c_init(void) {
282282
} else {
283283
crc32c = crc32c_sw;
284284
}
285-
return true;
286-
}();
285+
return ret;
286+
}(true);
287287
(void)bInit;
288288
}
289289

@@ -408,11 +408,11 @@ static void crc32c_init_sw_little(void) {
408408
uint32_t crc32c_sw_little(uint32_t crc, void const *buf, size_t len) {
409409
unsigned char const *next = static_cast<unsigned char const*>(buf);
410410

411-
static bool bInit = []()
411+
static bool bInit = [](bool ret)
412412
{
413413
crc32c_init_sw_little();
414-
return true;
415-
}();
414+
return ret;
415+
}(true);
416416
(void)bInit;
417417

418418
crc = ~crc;

frmts/zarr/vsikerchunk_json_ref.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ class VSIKerchunkJSONRefFileSystem final : public VSIFilesystemHandler
129129
public:
130130
VSIKerchunkJSONRefFileSystem()
131131
{
132-
IsFileSystemInstantiated() = true;
132+
bool *pbInstantiated = &IsFileSystemInstantiated();
133+
*pbInstantiated = true;
133134
}
134135

135136
~VSIKerchunkJSONRefFileSystem() override
136137
{
137-
IsFileSystemInstantiated() = false;
138+
bool *pbInstantiated = &IsFileSystemInstantiated();
139+
*pbInstantiated = false;
138140
}
139141

140142
static bool &IsFileSystemInstantiated()

frmts/zarr/vsikerchunk_parquet_ref.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class VSIKerchunkParquetRefFileSystem final : public VSIFilesystemHandler
6060
public:
6161
VSIKerchunkParquetRefFileSystem()
6262
{
63-
IsFileSystemInstantiated() = true;
63+
bool *pbInstantiated = &IsFileSystemInstantiated();
64+
*pbInstantiated = true;
6465
}
6566

6667
~VSIKerchunkParquetRefFileSystem() override;
@@ -124,7 +125,8 @@ class VSIKerchunkParquetRefFileSystem final : public VSIFilesystemHandler
124125
VSIKerchunkParquetRefFileSystem::~VSIKerchunkParquetRefFileSystem()
125126
{
126127
CleanCache();
127-
IsFileSystemInstantiated() = false;
128+
bool *pbInstantiated = &IsFileSystemInstantiated();
129+
*pbInstantiated = false;
128130
}
129131

130132
/************************************************************************/

ogr/ogr_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ OGRGeometry CPL_DLL *OGRGeometryFromEWKB(GByte *pabyWKB, int nLength,
192192
int *pnSRID, int bIsPostGIS1_EWKB);
193193
OGRGeometry CPL_DLL *OGRGeometryFromHexEWKB(const char *pszBytea, int *pnSRID,
194194
int bIsPostGIS1_EWKB);
195-
char CPL_DLL *OGRGeometryToHexEWKB(OGRGeometry *poGeometry, int nSRSId,
195+
char CPL_DLL *OGRGeometryToHexEWKB(const OGRGeometry *poGeometry, int nSRSId,
196196
int nPostGISMajor, int nPostGISMinor);
197197

198198
/************************************************************************/

ogr/ogrgeometry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7280,7 +7280,7 @@ OGRGeometry *OGRGeometryFromHexEWKB(const char *pszBytea, int *pnSRID,
72807280
/* OGRGeometryToHexEWKB() */
72817281
/************************************************************************/
72827282

7283-
char *OGRGeometryToHexEWKB(OGRGeometry *poGeometry, int nSRSId,
7283+
char *OGRGeometryToHexEWKB(const OGRGeometry *poGeometry, int nSRSId,
72847284
int nPostGISMajor, int nPostGISMinor)
72857285
{
72867286
const size_t nWkbSize = poGeometry->WkbSize();

ogr/ogrsf_frmts/amigocloud/ogramigocloudtablelayer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,15 @@ OGRErr OGRAmigoCloudTableLayer::ICreateFeature(OGRFeature *poFeature)
420420
// Add geometry field
421421
for (int i = 0; i < poFeatureDefn->GetGeomFieldCount(); i++)
422422
{
423-
if (poFeature->GetGeomFieldRef(i) == nullptr)
423+
const OGRGeometry *poGeom = poFeature->GetGeomFieldRef(i);
424+
if (poGeom == nullptr)
424425
continue;
425426

426427
record << "\""
427428
<< OGRAMIGOCLOUDJsonEncode(
428429
poFeatureDefn->GetGeomFieldDefn(i)->GetNameRef())
429430
<< "\":";
430431

431-
OGRGeometry *poGeom = poFeature->GetGeomFieldRef(i);
432-
if (poGeom == nullptr)
433-
continue;
434-
435432
OGRAmigoCloudGeomFieldDefn *poGeomFieldDefn =
436433
cpl::down_cast<OGRAmigoCloudGeomFieldDefn *>(
437434
poFeatureDefn->GetGeomFieldDefn(i));

ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ bool FGdbDataSource::LoadLayers(const std::wstring &root)
404404
m_osFSName, CPLSPrintf("a%08x", iGDBItems + 1), "gdbtable");
405405
std::unique_ptr<GDALDataset> poGDBItems(GDALDataset::Open(
406406
osGDBItems.c_str(), GDAL_OF_VECTOR, apszDrivers, nullptr, nullptr));
407-
if (poGDBItems != nullptr && poGDBItems->GetLayer(0) != nullptr)
407+
if (poGDBItems != nullptr)
408408
{
409409
if (OGRLayer *poItemsLayer = poGDBItems->GetLayer(0))
410410
{

0 commit comments

Comments
 (0)