Skip to content

Commit 0224c00

Browse files
authored
Merge pull request OSGeo#11568 from rouault/cppcheck_master_duplicateBreak
Fix duplicateBreak warnings with cppcheck master
2 parents 75c85b4 + acc669b commit 0224c00

File tree

3 files changed

+48
-33
lines changed

3 files changed

+48
-33
lines changed

ogr/ogr_api.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ int OGR_G_GetPoints(OGRGeometryH hGeom, void *pabyX, int nXStride, void *pabyY,
359359
{
360360
VALIDATE_POINTER1(hGeom, "OGR_G_GetPoints", 0);
361361

362+
int ret = 0;
362363
switch (wkbFlatten(ToPointer(hGeom)->getGeometryType()))
363364
{
364365
case wkbPoint:
@@ -370,25 +371,27 @@ int OGR_G_GetPoints(OGRGeometryH hGeom, void *pabyX, int nXStride, void *pabyY,
370371
*(static_cast<double *>(pabyY)) = poPoint->getY();
371372
if (pabyZ)
372373
*(static_cast<double *>(pabyZ)) = poPoint->getZ();
373-
return 1;
374+
ret = 1;
375+
break;
374376
}
375-
break;
376377

377378
case wkbLineString:
378379
case wkbCircularString:
379380
{
380381
OGRSimpleCurve *poSC = ToPointer(hGeom)->toSimpleCurve();
381382
poSC->getPoints(pabyX, nXStride, pabyY, nYStride, pabyZ, nZStride);
382-
return poSC->getNumPoints();
383+
ret = poSC->getNumPoints();
384+
break;
383385
}
384-
break;
385386

386387
default:
388+
{
387389
CPLError(CE_Failure, CPLE_NotSupported,
388390
"Incompatible geometry for operation");
389-
return 0;
390391
break;
392+
}
391393
}
394+
return ret;
392395
}
393396

394397
/************************************************************************/
@@ -429,6 +432,7 @@ int OGR_G_GetPointsZM(OGRGeometryH hGeom, void *pabyX, int nXStride,
429432
{
430433
VALIDATE_POINTER1(hGeom, "OGR_G_GetPointsZM", 0);
431434

435+
int ret = 0;
432436
switch (wkbFlatten(ToPointer(hGeom)->getGeometryType()))
433437
{
434438
case wkbPoint:
@@ -442,26 +446,29 @@ int OGR_G_GetPointsZM(OGRGeometryH hGeom, void *pabyX, int nXStride,
442446
*static_cast<double *>(pabyZ) = poPoint->getZ();
443447
if (pabyM)
444448
*static_cast<double *>(pabyM) = poPoint->getM();
445-
return 1;
449+
ret = 1;
450+
break;
446451
}
447-
break;
448452

449453
case wkbLineString:
450454
case wkbCircularString:
451455
{
452456
OGRSimpleCurve *poSC = ToPointer(hGeom)->toSimpleCurve();
453457
poSC->getPoints(pabyX, nXStride, pabyY, nYStride, pabyZ, nZStride,
454458
pabyM, nMStride);
455-
return poSC->getNumPoints();
459+
ret = poSC->getNumPoints();
460+
break;
456461
}
457-
break;
458462

459463
default:
464+
{
460465
CPLError(CE_Failure, CPLE_NotSupported,
461466
"Incompatible geometry for operation");
462-
return 0;
463467
break;
468+
}
464469
}
470+
471+
return ret;
465472
}
466473

467474
/************************************************************************/

ogr/ogrsf_frmts/generic/ogr_gensql.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -1387,19 +1387,19 @@ static CPLString GetFilterForJoin(swq_expr_node *poExpr, OGRFeature *poSrcFeat,
13871387
const OGRField *psSrcField =
13881388
poSrcFeat->GetRawFieldRef(poExpr->field_index);
13891389

1390+
CPLString osRet;
13901391
switch (ePrimaryFieldType)
13911392
{
13921393
case OFTInteger:
1393-
return CPLString().Printf("%d", psSrcField->Integer);
1394+
osRet.Printf("%d", psSrcField->Integer);
13941395
break;
13951396

13961397
case OFTInteger64:
1397-
return CPLString().Printf(CPL_FRMT_GIB,
1398-
psSrcField->Integer64);
1398+
osRet.Printf(CPL_FRMT_GIB, psSrcField->Integer64);
13991399
break;
14001400

14011401
case OFTReal:
1402-
return CPLString().Printf("%.17g", psSrcField->Real);
1402+
osRet.Printf("%.17g", psSrcField->Real);
14031403
break;
14041404

14051405
case OFTString:
@@ -1408,18 +1408,19 @@ static CPLString GetFilterForJoin(swq_expr_node *poExpr, OGRFeature *poSrcFeat,
14081408
psSrcField->String,
14091409
static_cast<int>(strlen(psSrcField->String)),
14101410
CPLES_SQL);
1411-
CPLString osRes = "'";
1412-
osRes += pszEscaped;
1413-
osRes += "'";
1411+
osRet = "'";
1412+
osRet += pszEscaped;
1413+
osRet += "'";
14141414
CPLFree(pszEscaped);
1415-
return osRes;
1415+
break;
14161416
}
1417-
break;
14181417

14191418
default:
14201419
CPLAssert(false);
1421-
return "";
1420+
break;
14221421
}
1422+
1423+
return osRet;
14231424
}
14241425
}
14251426

ogr/ogrsf_frmts/mitab/mitab_imapinfofile.cpp

+20-13
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ TABFeature *IMapInfoFile::CreateTABFeature(OGRFeature *poFeature)
297297
*------------------------------------------------------------*/
298298
case wkbPolygon:
299299
case wkbMultiPolygon:
300+
{
300301
poTABFeature = new TABRegion(poFeature->GetDefnRef());
301302
if (poFeature->GetStyleString())
302303
{
@@ -308,11 +309,13 @@ TABFeature *IMapInfoFile::CreateTABFeature(OGRFeature *poFeature)
308309
poFeature->GetStyleString());
309310
}
310311
break;
312+
}
311313
/*-------------------------------------------------------------
312314
* LINE/PLINE/MULTIPLINE
313315
*------------------------------------------------------------*/
314316
case wkbLineString:
315317
case wkbMultiLineString:
318+
{
316319
poTABFeature = new TABPolyline(poFeature->GetDefnRef());
317320
if (poFeature->GetStyleString())
318321
{
@@ -322,6 +325,7 @@ TABFeature *IMapInfoFile::CreateTABFeature(OGRFeature *poFeature)
322325
poFeature->GetStyleString());
323326
}
324327
break;
328+
}
325329
/*-------------------------------------------------------------
326330
* Collection types that are not directly supported... convert
327331
* to multiple features in output file through recursive calls.
@@ -332,38 +336,41 @@ TABFeature *IMapInfoFile::CreateTABFeature(OGRFeature *poFeature)
332336
OGRErr eStatus = OGRERR_NONE;
333337
assert(poGeom); // for clang static analyzer
334338
OGRGeometryCollection *poColl = poGeom->toGeometryCollection();
335-
OGRFeature *poTmpFeature = poFeature->Clone();
339+
auto poTmpFeature = std::unique_ptr<OGRFeature>(poFeature->Clone());
336340

337341
for (int i = 0; eStatus == OGRERR_NONE && poColl != nullptr &&
338342
i < poColl->getNumGeometries();
339343
i++)
340344
{
341345
poTmpFeature->SetFID(OGRNullFID);
342346
poTmpFeature->SetGeometry(poColl->getGeometryRef(i));
343-
eStatus = ICreateFeature(poTmpFeature);
347+
eStatus = ICreateFeature(poTmpFeature.get());
344348
}
345-
delete poTmpFeature;
346-
return nullptr;
349+
break;
347350
}
348-
break;
351+
349352
/*-------------------------------------------------------------
350353
* Unsupported type.... convert to MapInfo geometry NONE
351354
*------------------------------------------------------------*/
352-
case wkbUnknown:
353355
default:
356+
{
354357
poTABFeature = new TABFeature(poFeature->GetDefnRef());
355358
break;
359+
}
356360
}
357361

358-
if (poGeom != nullptr)
359-
poTABFeature->SetGeometryDirectly(poGeom->clone());
360-
361-
for (int i = 0; i < poFeature->GetDefnRef()->GetFieldCount(); i++)
362+
if (poTABFeature)
362363
{
363-
poTABFeature->SetField(i, poFeature->GetRawFieldRef(i));
364-
}
364+
if (poGeom != nullptr)
365+
poTABFeature->SetGeometryDirectly(poGeom->clone());
365366

366-
poTABFeature->SetFID(poFeature->GetFID());
367+
for (int i = 0; i < poFeature->GetDefnRef()->GetFieldCount(); i++)
368+
{
369+
poTABFeature->SetField(i, poFeature->GetRawFieldRef(i));
370+
}
371+
372+
poTABFeature->SetFID(poFeature->GetFID());
373+
}
367374

368375
return poTABFeature;
369376
}

0 commit comments

Comments
 (0)