From 306655c7d10c48f18c6f46e8d6410a31b411d229 Mon Sep 17 00:00:00 2001 From: AbelPau Date: Wed, 17 Apr 2024 05:25:02 +0200 Subject: [PATCH] Solving some errors in DBF's results Going back to strcpy instead of memset Fixing a recently added error about the umber of bytes to be copyied Link updated Solving ASSAN errors. Overfloat Making safer a strcpy + eliminating an invalid comment Fixing a ptrnull acces when creating an empty feature. --- ogr/ogrsf_frmts/miramon/mm_gdal_functions.c | 3 +- ogr/ogrsf_frmts/miramon/mm_gdal_functions.h | 3 ++ ogr/ogrsf_frmts/miramon/mm_wrlayr.c | 43 +++++++++++++++++---- ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp | 1 - 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/ogr/ogrsf_frmts/miramon/mm_gdal_functions.c b/ogr/ogrsf_frmts/miramon/mm_gdal_functions.c index 2b6d87a1f455..dc8c179a3401 100644 --- a/ogr/ogrsf_frmts/miramon/mm_gdal_functions.c +++ b/ogr/ogrsf_frmts/miramon/mm_gdal_functions.c @@ -2167,7 +2167,6 @@ int MM_SprintfDoubleSignifFigures(char *szChain, size_t size_szChain, int retorn, exponent; char *ptr; - char szChain_retorn[MM_CHARACTERS_DOUBLE + 1]; #define N_POWERS MM_MAX_XS_DOUBLE /* This expression ensures that no garbage is written in @@ -2235,7 +2234,6 @@ int MM_SprintfDoubleSignifFigures(char *szChain, size_t size_szChain, return 0; exponent = atoi(ptr + 1); - dfRealValue = CPLAtof(szChain); return sprintf(szChain, "%.*f", (nSignifFigures - exponent - 1) > 0 ? (nSignifFigures - exponent - 1) @@ -2408,6 +2406,7 @@ int MM_SecureCopyStringFieldValue(char **pszStringDst, const char *pszStringSrc, (*pszStringDst) = new_ptr; *nStringCurrentLength = (MM_EXT_DBF_N_FIELDS)(strlen(pszStringSrc) + 1); } + strcpy(*pszStringDst, pszStringSrc); return 0; } diff --git a/ogr/ogrsf_frmts/miramon/mm_gdal_functions.h b/ogr/ogrsf_frmts/miramon/mm_gdal_functions.h index f8c3e634a1c3..74060fb3707d 100644 --- a/ogr/ogrsf_frmts/miramon/mm_gdal_functions.h +++ b/ogr/ogrsf_frmts/miramon/mm_gdal_functions.h @@ -129,6 +129,9 @@ int MM_ModifyFieldNameAndDescriptorIfPresentBD_XP( struct MM_FIELD *camp, struct MM_DATA_BASE_XP *bd_xp, MM_BOOLEAN no_modifica_descriptor, size_t mida_nom); +int MMWritePreformatedValueToRecordDBXP( + struct MiraMonVectLayerInfo *hMiraMonLayer, char *registre, + const struct MM_FIELD *camp, const char *valor); int MMWriteValueToRecordDBXP(struct MiraMonVectLayerInfo *hMiraMonLayer, char *registre, const struct MM_FIELD *camp, const void *valor, MM_BOOLEAN is_64); diff --git a/ogr/ogrsf_frmts/miramon/mm_wrlayr.c b/ogr/ogrsf_frmts/miramon/mm_wrlayr.c index 15cfada240a4..ced4bf113da0 100644 --- a/ogr/ogrsf_frmts/miramon/mm_wrlayr.c +++ b/ogr/ogrsf_frmts/miramon/mm_wrlayr.c @@ -2948,7 +2948,7 @@ int MMAppendIntegerDependingOnVersion( /* -------------------------------------------------------------------- */ /* Layer: Reading and writing layer sections */ /* This code follows the specifications of the following document: */ -/* https://www.miramon.cat/new_note/usa/notes/ \ */ +/* https://www.miramon.cat/new_note/eng/notes/ \ */ /* FormatFitxersTopologicsMiraMon.pdf */ /* -------------------------------------------------------------------- */ int MMReadAHArcSection(struct MiraMonVectLayerInfo *hMiraMonLayer) @@ -6652,6 +6652,34 @@ MMWriteValueToszStringToOperate(struct MiraMonVectLayerInfo *hMiraMonLayer, return 0; } +int MMWritePreformatedValueToRecordDBXP( + struct MiraMonVectLayerInfo *hMiraMonLayer, char *registre, + const struct MM_FIELD *camp, const char *valor) +{ + if (!hMiraMonLayer) + return 1; + + if (!camp) + return 0; + + if (MMResizeStringToOperateIfNeeded(hMiraMonLayer, + camp->BytesPerField + 10)) + return 1; + + if (!valor) + *hMiraMonLayer->szStringToOperate = '\0'; + else + { + snprintf(hMiraMonLayer->szStringToOperate, + (size_t)hMiraMonLayer->nNumStringToOperate, "%*s", + camp->BytesPerField, valor); + } + + memcpy(registre + camp->AccumulatedBytes, hMiraMonLayer->szStringToOperate, + camp->BytesPerField); + return 0; +} + int MMWriteValueToRecordDBXP(struct MiraMonVectLayerInfo *hMiraMonLayer, char *registre, const struct MM_FIELD *camp, const void *valor, MM_BOOLEAN is_64) @@ -6712,12 +6740,13 @@ static int MMAddFeatureRecordToMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer, 'N' && !pBD_XP->pField[nIField + nNumPrivateMMField].Is64)) { - const struct MM_FIELD *camp; - - camp = pBD_XP->pField + nIField + nNumPrivateMMField; - memcpy(pszRecordOnCourse + camp->AccumulatedBytes, - hMMFeature->pRecords[nIRecord].pField[nIField].pDinValue, - camp->BytesPerField); + if (MMWritePreformatedValueToRecordDBXP( + hMiraMonLayer, pszRecordOnCourse, + pBD_XP->pField + nIField + nNumPrivateMMField, + hMMFeature->pRecords[nIRecord] + .pField[nIField] + .pDinValue)) + return 1; } else if (pBD_XP->pField[nIField + nNumPrivateMMField].FieldType == 'N') diff --git a/ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp b/ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp index b894f85b3be6..f2ad8344d88d 100644 --- a/ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp +++ b/ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp @@ -2365,7 +2365,6 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature) hMMFeature.pRecords[0].nNumField)) return OGRERR_NOT_ENOUGH_MEMORY; - // MiraMon encoding is ISO 8859-1 (Latin1) -> Recode from UTF-8 if (MM_SecureCopyStringFieldValue( &hMMFeature.pRecords[0].pField[iField].pDinValue, pszRawValue,