Skip to content

Commit

Permalink
Solving some pointer errors and deleting a not needed parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelPau committed Apr 12, 2024
1 parent 8e05049 commit 6dbc058
Showing 1 changed file with 54 additions and 60 deletions.
114 changes: 54 additions & 60 deletions ogr/ogrsf_frmts/miramon/mm_wrlayr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3961,7 +3961,8 @@ static int MMCreateFeaturePolOrArc(struct MiraMonVectLayerInfo *hMiraMonLayer,
MMCPLDebug("MiraMon", "Creating MiraMon database");
if (MMCreateMMDB(hMiraMonLayer))
return MM_FATAL_ERROR_WRITING_FEATURES;
MMCPLDebug("MiraMon", "MiraMon database created");
MMCPLDebug("MiraMon", "MiraMon database created. "
"Creating features...");
}
}
else
Expand All @@ -3971,7 +3972,8 @@ static int MMCreateFeaturePolOrArc(struct MiraMonVectLayerInfo *hMiraMonLayer,
MMCPLDebug("MiraMon", "Creating MiraMon database");
if (MMCreateMMDB(hMiraMonLayer))
return MM_FATAL_ERROR_WRITING_FEATURES;
MMCPLDebug("MiraMon", "MiraMon database created");
MMCPLDebug("MiraMon", "MiraMon database created. "
"Creating features...");

// Universal polygon have a record with ID_GRAFIC=0 and blancs
if (MMAddPolygonRecordToMMDB(hMiraMonLayer, nullptr, 0, 0, nullptr))
Expand Down Expand Up @@ -6726,7 +6728,7 @@ static int MMAddFeatureRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
static int MMDetectAndFixDBFWidthChange(
struct MiraMonVectLayerInfo *hMiraMonLayer,
struct MiraMonFeature *hMMFeature, struct MMAdmDatabase *pMMAdmDB,
struct MM_FLUSH_INFO *pFlushRecList, MM_EXT_DBF_N_FIELDS nNumPrivateMMField,
MM_EXT_DBF_N_FIELDS nNumPrivateMMField,
MM_EXT_DBF_N_MULTIPLE_RECORDS nIRecord, MM_EXT_DBF_N_FIELDS nIField)
{
if (!hMiraMonLayer)
Expand All @@ -6751,9 +6753,9 @@ static int MMDetectAndFixDBFWidthChange(
{
if (nIRecord + 1 < hMMFeature->nNumMRecords)
{
if (MMDetectAndFixDBFWidthChange(
hMiraMonLayer, hMMFeature, pMMAdmDB, pFlushRecList,
nNumPrivateMMField, nIRecord + 1, 0))
if (MMDetectAndFixDBFWidthChange(hMiraMonLayer, hMMFeature,
pMMAdmDB, nNumPrivateMMField,
nIRecord + 1, 0))
return 1;
}
else
Expand All @@ -6763,9 +6765,9 @@ static int MMDetectAndFixDBFWidthChange(
{
if (nIField + 1 < hMMFeature->pRecords[nIRecord].nNumField)
{
if (MMDetectAndFixDBFWidthChange(
hMiraMonLayer, hMMFeature, pMMAdmDB, pFlushRecList,
nNumPrivateMMField, nIRecord, nIField + 1))
if (MMDetectAndFixDBFWidthChange(hMiraMonLayer, hMMFeature,
pMMAdmDB, nNumPrivateMMField,
nIRecord, nIField + 1))
return 1;
}
else
Expand All @@ -6788,30 +6790,28 @@ int MMAddDBFRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
if (!hMiraMonLayer)
return MM_FATAL_ERROR_WRITING_FEATURES;

// Adding record to the MiraMon table (extended DBF)
// Flush settings
pFlushRecList = &hMiraMonLayer->MMAdmDBWriting.FlushRecList;
pFlushRecList->pBlockWhereToSaveOrRead =
(void *)hMiraMonLayer->MMAdmDBWriting.pRecList;

pFlushRecList->pBlockToBeSaved =
(void *)hMiraMonLayer->MMAdmDBWriting.szRecordOnCourse;

pBD_XP = hMiraMonLayer->MMAdmDBWriting.pMMBDXP;

// Test length
if (hMMFeature && hMMFeature->nNumMRecords &&
hMMFeature->pRecords[0].nNumField)
{
if (MMDetectAndFixDBFWidthChange(
hMiraMonLayer, hMMFeature, &hMiraMonLayer->MMAdmDBWriting,
pFlushRecList, nNumPrivateMMField, 0, 0))
if (MMDetectAndFixDBFWidthChange(hMiraMonLayer, hMMFeature,
&hMiraMonLayer->MMAdmDBWriting,
nNumPrivateMMField, 0, 0))
return MM_FATAL_ERROR_WRITING_FEATURES;
}

// Adding record to the MiraMon table (extended DBF)
// Flush settings
pFlushRecList = &hMiraMonLayer->MMAdmDBWriting.FlushRecList;
pFlushRecList->pBlockWhereToSaveOrRead =
(void *)hMiraMonLayer->MMAdmDBWriting.pRecList;

pFlushRecList->pBlockToBeSaved =
(void *)hMiraMonLayer->MMAdmDBWriting.szRecordOnCourse;
pFlushRecList->SizeOfBlockToBeSaved = pBD_XP->BytesPerRecord;

if (MMAddFeatureRecordToMMDB(
hMiraMonLayer, hMMFeature, &hMiraMonLayer->MMAdmDBWriting,
hMiraMonLayer->MMAdmDBWriting.szRecordOnCourse, pFlushRecList,
Expand Down Expand Up @@ -6851,12 +6851,6 @@ int MMAddPointRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
return MM_STOP_WRITING_FEATURES;
}

// Adding record to the MiraMon table (extended DBF)
// Flush settings
pFlushRecList = &hMiraMonLayer->MMPoint.MMAdmDB.FlushRecList;
pFlushRecList->pBlockWhereToSaveOrRead =
(void *)hMiraMonLayer->MMPoint.MMAdmDB.pRecList;

pBD_XP = hMiraMonLayer->MMPoint.MMAdmDB.pMMBDXP;

// Test length
Expand All @@ -6873,9 +6867,9 @@ int MMAddPointRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
// GDAL fields
if (hMMFeature->nNumMRecords && hMMFeature->pRecords[0].nNumField)
{
if (MMDetectAndFixDBFWidthChange(
hMiraMonLayer, hMMFeature, &hMiraMonLayer->MMPoint.MMAdmDB,
pFlushRecList, nNumPrivateMMField, 0, 0))
if (MMDetectAndFixDBFWidthChange(hMiraMonLayer, hMMFeature,
&hMiraMonLayer->MMPoint.MMAdmDB,
nNumPrivateMMField, 0, 0))
return MM_FATAL_ERROR_WRITING_FEATURES;
}

Expand All @@ -6886,9 +6880,16 @@ int MMAddPointRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
hMiraMonLayer->MMPoint.MMAdmDB.szRecordOnCourse,
pBD_XP->pField, &nElemCount, TRUE);

// Adding record to the MiraMon table (extended DBF)
// Flush settings
pFlushRecList = &hMiraMonLayer->MMPoint.MMAdmDB.FlushRecList;
pFlushRecList->pBlockWhereToSaveOrRead =
(void *)hMiraMonLayer->MMPoint.MMAdmDB.pRecList;

pFlushRecList->pBlockToBeSaved =
(void *)hMiraMonLayer->MMPoint.MMAdmDB.szRecordOnCourse;
pFlushRecList->SizeOfBlockToBeSaved = pBD_XP->BytesPerRecord;

if (MMAddFeatureRecordToMMDB(
hMiraMonLayer, hMMFeature, &hMiraMonLayer->MMPoint.MMAdmDB,
hMiraMonLayer->MMPoint.MMAdmDB.szRecordOnCourse, pFlushRecList,
Expand Down Expand Up @@ -6939,18 +6940,8 @@ int MMAddArcRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
}
}

// Adding record to the MiraMon table (extended DBF)
// Flush settings
pFlushRecList = &pMMArcLayer->MMAdmDB.FlushRecList;
pFlushRecList->pBlockWhereToSaveOrRead =
(void *)pMMArcLayer->MMAdmDB.pRecList;

pBD_XP = pMMArcLayer->MMAdmDB.pMMBDXP;

pFlushRecList->SizeOfBlockToBeSaved = pBD_XP->BytesPerRecord;
pFlushRecList->pBlockToBeSaved =
(void *)pMMArcLayer->MMAdmDB.szRecordOnCourse;

// Test length
// Private fields
// ID_GRAFIC
Expand Down Expand Up @@ -6998,15 +6989,11 @@ int MMAddArcRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
{
if (hMMFeature->nNumMRecords && hMMFeature->pRecords[0].nNumField)
{
if (MMDetectAndFixDBFWidthChange(
hMiraMonLayer, hMMFeature, &pMMArcLayer->MMAdmDB,
pFlushRecList, nNumPrivateMMField, 0, 0))
if (MMDetectAndFixDBFWidthChange(hMiraMonLayer, hMMFeature,
&pMMArcLayer->MMAdmDB,
nNumPrivateMMField, 0, 0))
return MM_FATAL_ERROR_WRITING_FEATURES;
}

// Reassign the point because the function can realloc it.
pFlushRecList->pBlockToBeSaved =
(void *)pMMArcLayer->MMAdmDB.szRecordOnCourse;
}

// Now length is sure, write
Expand All @@ -7031,6 +7018,16 @@ int MMAddArcRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
hMiraMonLayer, pMMArcLayer->MMAdmDB.szRecordOnCourse,
pBD_XP->pField + 4, &pArcHeader->nLastIdNode, TRUE);

// Adding record to the MiraMon table (extended DBF)
// Flush settings
pFlushRecList = &pMMArcLayer->MMAdmDB.FlushRecList;
pFlushRecList->pBlockWhereToSaveOrRead =
(void *)pMMArcLayer->MMAdmDB.pRecList;

pFlushRecList->SizeOfBlockToBeSaved = pBD_XP->BytesPerRecord;
pFlushRecList->pBlockToBeSaved =
(void *)pMMArcLayer->MMAdmDB.szRecordOnCourse;

if (hMiraMonLayer->bIsPolygon)
{
if (MMAppendBlockToBuffer(pFlushRecList))
Expand Down Expand Up @@ -7165,18 +7162,8 @@ int MMAddPolygonRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
(hMMFeature ? hMMFeature->nNumMRecords : 0)))
return MM_STOP_WRITING_FEATURES;

// Adding record to the MiraMon table (extended DBF)
// Flush settings
pFlushRecList = &hMiraMonLayer->MMPolygon.MMAdmDB.FlushRecList;
pFlushRecList->pBlockWhereToSaveOrRead =
(void *)hMiraMonLayer->MMPolygon.MMAdmDB.pRecList;

pBD_XP = hMiraMonLayer->MMPolygon.MMAdmDB.pMMBDXP;

pFlushRecList->SizeOfBlockToBeSaved = pBD_XP->BytesPerRecord;
pFlushRecList->pBlockToBeSaved =
(void *)hMiraMonLayer->MMPolygon.MMAdmDB.szRecordOnCourse;

// Test length
// Private fields
// ID_GRAFIC
Expand Down Expand Up @@ -7242,12 +7229,19 @@ int MMAddPolygonRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
if (hMMFeature && hMMFeature->nNumMRecords &&
hMMFeature->pRecords[0].nNumField)
{
if (MMDetectAndFixDBFWidthChange(
hMiraMonLayer, hMMFeature, &hMiraMonLayer->MMPolygon.MMAdmDB,
pFlushRecList, nNumPrivateMMField, 0, 0))
if (MMDetectAndFixDBFWidthChange(hMiraMonLayer, hMMFeature,
&hMiraMonLayer->MMPolygon.MMAdmDB,
nNumPrivateMMField, 0, 0))
return MM_FATAL_ERROR_WRITING_FEATURES;
}

// Adding record to the MiraMon table (extended DBF)
// Flush settings
pFlushRecList = &hMiraMonLayer->MMPolygon.MMAdmDB.FlushRecList;
pFlushRecList->pBlockWhereToSaveOrRead =
(void *)hMiraMonLayer->MMPolygon.MMAdmDB.pRecList;

pFlushRecList->SizeOfBlockToBeSaved = pBD_XP->BytesPerRecord;
pFlushRecList->pBlockToBeSaved =
(void *)hMiraMonLayer->MMPolygon.MMAdmDB.szRecordOnCourse;

Expand Down

0 comments on commit 6dbc058

Please sign in to comment.