Skip to content

Commit 8e46598

Browse files
committed
OCI: fix dangerousTypeCast cppcheck warnings
1 parent 8148893 commit 8e46598

File tree

7 files changed

+246
-208
lines changed

7 files changed

+246
-208
lines changed

ogr/ogrsf_frmts/oci/fastload.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,22 @@ int main()
8080
int iBindRow;
8181
for (iBindRow = 0; iBindRow < 100; iBindRow++)
8282
{
83-
if (oSession.Failed(OCIObjectNew(oSession.hEnv, oSession.hError,
84-
oSession.hSvcCtx, OCI_TYPECODE_VARRAY,
85-
oSession.hElemInfoTDO, (dvoid *)NULL,
86-
OCI_DURATION_SESSION, FALSE,
87-
(dvoid **)(aphElemInfos + iBindRow)),
88-
"OCIObjectNew()"))
83+
if (oSession.Failed(
84+
OCIObjectNew(
85+
oSession.hEnv, oSession.hError, oSession.hSvcCtx,
86+
OCI_TYPECODE_VARRAY, oSession.hElemInfoTDO,
87+
static_cast<dvoid *>(NULL), OCI_DURATION_SESSION, FALSE,
88+
reinterpret_cast<dvoid **>(aphElemInfos + iBindRow)),
89+
"OCIObjectNew()"))
8990
exit(1);
9091

91-
if (oSession.Failed(OCIObjectNew(oSession.hEnv, oSession.hError,
92-
oSession.hSvcCtx, OCI_TYPECODE_VARRAY,
93-
oSession.hOrdinatesTDO, (dvoid *)NULL,
94-
OCI_DURATION_SESSION, FALSE,
95-
(dvoid **)(aphOrdinates + iBindRow)),
96-
"OCIObjectNew()"))
92+
if (oSession.Failed(
93+
OCIObjectNew(
94+
oSession.hEnv, oSession.hError, oSession.hSvcCtx,
95+
OCI_TYPECODE_VARRAY, oSession.hOrdinatesTDO,
96+
static_cast<dvoid *>(NULL), OCI_DURATION_SESSION, FALSE,
97+
reinterpret_cast<dvoid **>(aphOrdinates + iBindRow)),
98+
"OCIObjectNew()"))
9799
exit(1);
98100
}
99101

@@ -126,9 +128,9 @@ int main()
126128
for (i = 0; i < nElemInfoCount; i++)
127129
{
128130
if (oSession.Failed(
129-
OCINumberFromInt(oSession.hError, (dvoid *)(anElemInfo + i),
130-
(uword)sizeof(int), OCI_NUMBER_SIGNED,
131-
&oci_number),
131+
OCINumberFromInt(
132+
oSession.hError, static_cast<dvoid *>(anElemInfo + i),
133+
(uword)sizeof(int), OCI_NUMBER_SIGNED, &oci_number),
132134
"OCINumberFromInt"))
133135
exit(1);
134136

@@ -154,15 +156,16 @@ int main()
154156
// Prepare the VARRAY of ordinate values.
155157
for (i = 0; i < nOrdCount; i++)
156158
{
157-
if (oSession.Failed(OCINumberFromReal(oSession.hError,
158-
(dvoid *)(adfOrdinates + i),
159-
(uword)sizeof(double),
160-
&oci_number),
161-
"OCINumberFromReal"))
159+
if (oSession.Failed(
160+
OCINumberFromReal(oSession.hError,
161+
static_cast<dvoid *>(adfOrdinates + i),
162+
(uword)sizeof(double), &oci_number),
163+
"OCINumberFromReal"))
162164
exit(1);
163165

164166
if (oSession.Failed(OCICollAppend(oSession.hEnv, oSession.hError,
165-
(dvoid *)&oci_number, (dvoid *)0,
167+
static_cast<dvoid *>(&oci_number),
168+
static_cast<dvoid *>(NULL),
166169
aphOrdinates[iRow]),
167170
"OCICollAppend"))
168171
exit(1);
@@ -175,16 +178,17 @@ int main()
175178
poInd->sdo_point._atomic = OCI_IND_NULL;
176179

177180
if (oSession.Failed(
178-
OCINumberFromInt(oSession.hError, (dvoid *)(anGType + iRow),
181+
OCINumberFromInt(oSession.hError,
182+
static_cast<dvoid *>(anGType + iRow),
179183
(uword)sizeof(int), OCI_NUMBER_SIGNED,
180184
&(poGeom->sdo_gtype)),
181185
"OCINumberFromInt"))
182186
exit(1);
183187

184188
if (oSession.Failed(
185-
OCINumberFromInt(oSession.hError, (dvoid *)(anSRID + iRow),
186-
(uword)sizeof(int), OCI_NUMBER_SIGNED,
187-
&(poGeom->sdo_srid)),
189+
OCINumberFromInt(
190+
oSession.hError, static_cast<dvoid *>(anSRID + iRow),
191+
(uword)sizeof(int), OCI_NUMBER_SIGNED, &(poGeom->sdo_srid)),
188192
"OCINumberFromInt"))
189193
exit(1);
190194

ogr/ogrsf_frmts/oci/ogrocidatasource.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ void OGROCIDataSource::ValidateLayer(const char *pszLayerName)
291291
/* -------------------------------------------------------------------- */
292292
/* Verify we have an FID and geometry column for this table. */
293293
/* -------------------------------------------------------------------- */
294-
OGROCITableLayer *poLayer = (OGROCITableLayer *)papoLayers[iLayer];
294+
OGROCITableLayer *poLayer =
295+
cpl::down_cast<OGROCITableLayer *>(papoLayers[iLayer]);
295296

296297
if (strlen(poLayer->GetFIDColumn()) == 0)
297298
{

ogr/ogrsf_frmts/oci/ogrocilayer.cpp

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ OGRFeature *OGROCILayer::GetNextRawFeature()
181181

182182
if (poFeature->GetGeometryRef() != nullptr && hLastGeom != nullptr)
183183
poSession->Failed(OCIObjectFree(poSession->hEnv, poSession->hError,
184-
(dvoid *)hLastGeom,
184+
static_cast<dvoid *>(hLastGeom),
185185
(ub2)OCI_OBJECTFREE_FORCE));
186186

187187
hLastGeom = nullptr;
@@ -228,20 +228,23 @@ int OGROCILayer::ExecuteQuery(const char *pszReqQuery)
228228
{
229229
OCIDefine *hGDefine = nullptr;
230230

231-
if (poSession->Failed(OCIDefineByPos(poStatement->GetStatement(),
232-
&hGDefine, poSession->hError,
233-
(ub4)iGeomColumn + 1,
234-
(dvoid *)nullptr, (sb4)0, SQLT_NTY,
235-
(dvoid *)nullptr, (ub2 *)nullptr,
236-
(ub2 *)nullptr, (ub4)OCI_DEFAULT),
237-
"OCIDefineByPos(geometry)"))
231+
if (poSession->Failed(
232+
OCIDefineByPos(poStatement->GetStatement(), &hGDefine,
233+
poSession->hError, (ub4)iGeomColumn + 1,
234+
static_cast<dvoid *>(nullptr), (sb4)0, SQLT_NTY,
235+
static_cast<dvoid *>(nullptr),
236+
static_cast<ub2 *>(nullptr),
237+
static_cast<ub2 *>(nullptr), (ub4)OCI_DEFAULT),
238+
"OCIDefineByPos(geometry)"))
238239
return FALSE;
239240

240241
if (poSession->Failed(
241242
OCIDefineObject(hGDefine, poSession->hError,
242-
poSession->hGeometryTDO, (dvoid **)&hLastGeom,
243-
(ub4 *)nullptr, (dvoid **)&hLastGeomInd,
244-
(ub4 *)nullptr),
243+
poSession->hGeometryTDO,
244+
reinterpret_cast<dvoid **>(&hLastGeom),
245+
static_cast<ub4 *>(nullptr),
246+
reinterpret_cast<dvoid **>(&hLastGeomInd),
247+
static_cast<ub4 *>(nullptr)),
245248
"OCIDefineObject"))
246249
return FALSE;
247250
}
@@ -270,16 +273,18 @@ OGRGeometry *OGROCILayer::TranslateGeometry()
270273
/* -------------------------------------------------------------------- */
271274
int nElemCount, nOrdCount;
272275

273-
if (poSession->Failed(OCICollSize(poSession->hEnv, poSession->hError,
274-
(OCIColl *)(hLastGeom->sdo_elem_info),
275-
&nElemCount),
276-
"OCICollSize(sdo_elem_info)"))
276+
if (poSession->Failed(
277+
OCICollSize(poSession->hEnv, poSession->hError,
278+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_elem_info),
279+
&nElemCount),
280+
"OCICollSize(sdo_elem_info)"))
277281
return nullptr;
278282

279-
if (poSession->Failed(OCICollSize(poSession->hEnv, poSession->hError,
280-
(OCIColl *)(hLastGeom->sdo_ordinates),
281-
&nOrdCount),
282-
"OCICollSize(sdo_ordinates)"))
283+
if (poSession->Failed(
284+
OCICollSize(poSession->hEnv, poSession->hError,
285+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_ordinates),
286+
&nOrdCount),
287+
"OCICollSize(sdo_ordinates)"))
283288
return nullptr;
284289

285290
/* -------------------------------------------------------------------- */
@@ -290,7 +295,7 @@ OGRGeometry *OGROCILayer::TranslateGeometry()
290295
if (poSession->Failed(OCINumberToInt(poSession->hError,
291296
&(hLastGeom->sdo_gtype),
292297
(uword)sizeof(int), OCI_NUMBER_SIGNED,
293-
(dvoid *)&nGType),
298+
static_cast<dvoid *>(&nGType)),
294299
"OCINumberToInt(GType)"))
295300
return nullptr;
296301

@@ -310,12 +315,12 @@ OGRGeometry *OGROCILayer::TranslateGeometry()
310315
double dfX, dfY, dfZ = 0.0;
311316

312317
OCINumberToReal(poSession->hError, &(hLastGeom->sdo_point.x),
313-
(uword)sizeof(double), (dvoid *)&dfX);
318+
(uword)sizeof(double), static_cast<dvoid *>(&dfX));
314319
OCINumberToReal(poSession->hError, &(hLastGeom->sdo_point.y),
315-
(uword)sizeof(double), (dvoid *)&dfY);
320+
(uword)sizeof(double), static_cast<dvoid *>(&dfY));
316321
if (hLastGeomInd->sdo_point.z == OCI_IND_NOTNULL)
317322
OCINumberToReal(poSession->hError, &(hLastGeom->sdo_point.z),
318-
(uword)sizeof(double), (dvoid *)&dfZ);
323+
(uword)sizeof(double), static_cast<dvoid *>(&dfZ));
319324

320325
if (nDimension == 3)
321326
return new OGRPoint(dfX, dfY, dfZ);
@@ -457,33 +462,38 @@ int OGROCILayer::LoadElementInfo(int iElement, int nElemCount,
457462
/* Get the details about element from the elem_info array. */
458463
/* -------------------------------------------------------------------- */
459464
OCICollGetElem(poSession->hEnv, poSession->hError,
460-
(OCIColl *)(hLastGeom->sdo_elem_info), (sb4)(iElement + 0),
461-
(boolean *)&bExists, (dvoid **)&hNumber, nullptr);
465+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_elem_info),
466+
(sb4)(iElement + 0), reinterpret_cast<boolean *>(&bExists),
467+
reinterpret_cast<dvoid **>(&hNumber), nullptr);
462468
OCINumberToInt(poSession->hError, hNumber, (uword)sizeof(ub4),
463-
OCI_NUMBER_UNSIGNED, (dvoid *)pnStartOrdinal);
469+
OCI_NUMBER_UNSIGNED, static_cast<dvoid *>(pnStartOrdinal));
464470

465471
OCICollGetElem(poSession->hEnv, poSession->hError,
466-
(OCIColl *)(hLastGeom->sdo_elem_info), (sb4)(iElement + 1),
467-
(boolean *)&bExists, (dvoid **)&hNumber, nullptr);
472+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_elem_info),
473+
(sb4)(iElement + 1), reinterpret_cast<boolean *>(&bExists),
474+
reinterpret_cast<dvoid **>(&hNumber), nullptr);
468475
OCINumberToInt(poSession->hError, hNumber, (uword)sizeof(ub4),
469-
OCI_NUMBER_UNSIGNED, (dvoid *)pnEType);
476+
OCI_NUMBER_UNSIGNED, static_cast<dvoid *>(pnEType));
470477

471478
OCICollGetElem(poSession->hEnv, poSession->hError,
472-
(OCIColl *)(hLastGeom->sdo_elem_info), (sb4)(iElement + 2),
473-
(boolean *)&bExists, (dvoid **)&hNumber, nullptr);
479+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_elem_info),
480+
(sb4)(iElement + 2), reinterpret_cast<boolean *>(&bExists),
481+
reinterpret_cast<dvoid **>(&hNumber), nullptr);
474482
OCINumberToInt(poSession->hError, hNumber, (uword)sizeof(ub4),
475-
OCI_NUMBER_UNSIGNED, (dvoid *)pnInterpretation);
483+
OCI_NUMBER_UNSIGNED, static_cast<dvoid *>(pnInterpretation));
476484

477485
if (iElement < nElemCount - 3)
478486
{
479487
ub4 nNextStartOrdinal;
480488

481489
OCICollGetElem(poSession->hEnv, poSession->hError,
482-
(OCIColl *)(hLastGeom->sdo_elem_info),
483-
(sb4)(iElement + 3), (boolean *)&bExists,
484-
(dvoid **)&hNumber, nullptr);
490+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_elem_info),
491+
(sb4)(iElement + 3),
492+
reinterpret_cast<boolean *>(&bExists),
493+
reinterpret_cast<dvoid **>(&hNumber), nullptr);
485494
OCINumberToInt(poSession->hError, hNumber, (uword)sizeof(ub4),
486-
OCI_NUMBER_UNSIGNED, (dvoid *)&nNextStartOrdinal);
495+
OCI_NUMBER_UNSIGNED,
496+
static_cast<dvoid *>(&nNextStartOrdinal));
487497

488498
*pnElemOrdCount = nNextStartOrdinal - *pnStartOrdinal;
489499
}
@@ -723,13 +733,15 @@ OGRGeometry *OGROCILayer::TranslateGeometryElement(int *piElement, int nGType,
723733
OGROCISession *poSession = poDS->GetSession();
724734

725735
if (poSession->Failed(OCICollSize(poSession->hEnv, poSession->hError,
726-
(OCIColl *)(hLastGeom->sdo_elem_info),
736+
reinterpret_cast<OCIColl *>(
737+
hLastGeom->sdo_elem_info),
727738
&nElemCount),
728739
"OCICollSize(sdo_elem_info)"))
729740
return nullptr;
730741

731742
if (poSession->Failed(OCICollSize(poSession->hEnv, poSession->hError,
732-
(OCIColl *)(hLastGeom->sdo_ordinates),
743+
reinterpret_cast<OCIColl *>(
744+
hLastGeom->sdo_ordinates),
733745
&nTotalOrdCount),
734746
"OCICollSize(sdo_ordinates)"))
735747
return nullptr;
@@ -802,22 +814,25 @@ int OGROCILayer::GetOrdinalPoint(int iOrdinal, int nDimension, double *pdfX,
802814
OCINumber *hNumber;
803815

804816
OCICollGetElem(poSession->hEnv, poSession->hError,
805-
(OCIColl *)(hLastGeom->sdo_ordinates), (sb4)iOrdinal + 0,
806-
(boolean *)&bExists, (dvoid **)&hNumber, nullptr);
817+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_ordinates),
818+
(sb4)iOrdinal + 0, reinterpret_cast<boolean *>(&bExists),
819+
reinterpret_cast<dvoid **>(&hNumber), nullptr);
807820
OCINumberToReal(poSession->hError, hNumber, (uword)sizeof(double),
808-
(dvoid *)pdfX);
821+
static_cast<dvoid *>(pdfX));
809822
OCICollGetElem(poSession->hEnv, poSession->hError,
810-
(OCIColl *)(hLastGeom->sdo_ordinates), (sb4)iOrdinal + 1,
811-
(boolean *)&bExists, (dvoid **)&hNumber, nullptr);
823+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_ordinates),
824+
(sb4)iOrdinal + 1, reinterpret_cast<boolean *>(&bExists),
825+
reinterpret_cast<dvoid **>(&hNumber), nullptr);
812826
OCINumberToReal(poSession->hError, hNumber, (uword)sizeof(double),
813-
(dvoid *)pdfY);
827+
static_cast<dvoid *>(pdfY));
814828
if (nDimension == 3)
815829
{
816830
OCICollGetElem(poSession->hEnv, poSession->hError,
817-
(OCIColl *)(hLastGeom->sdo_ordinates), (sb4)iOrdinal + 2,
818-
(boolean *)&bExists, (dvoid **)&hNumber, nullptr);
831+
reinterpret_cast<OCIColl *>(hLastGeom->sdo_ordinates),
832+
(sb4)iOrdinal + 2, reinterpret_cast<boolean *>(&bExists),
833+
reinterpret_cast<dvoid **>(&hNumber), nullptr);
819834
OCINumberToReal(poSession->hError, hNumber, (uword)sizeof(double),
820-
(dvoid *)pdfZ);
835+
static_cast<dvoid *>(pdfZ));
821836
}
822837

823838
return TRUE;

ogr/ogrsf_frmts/oci/ogrociselectlayer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ OGROCISelectLayer::ReadTableDefinition(OGROCIStatement *poCommand)
6868
ub2 nOCIType;
6969
ub4 nOCILen;
7070

71-
nStatus = OCIParamGet(poCommand->GetStatement(), OCI_HTYPE_STMT,
72-
poSession->hError, (dvoid **)&hParamDesc,
73-
(ub4)iParam + 1);
71+
nStatus = OCIParamGet(
72+
poCommand->GetStatement(), OCI_HTYPE_STMT, poSession->hError,
73+
reinterpret_cast<dvoid **>(&hParamDesc), (ub4)iParam + 1);
7474

7575
if (nStatus == OCI_ERROR)
7676
break;

0 commit comments

Comments
 (0)