Skip to content

Commit

Permalink
Solving some errors in DBF's results
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AbelPau committed Apr 17, 2024
1 parent 507012c commit 306655c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
3 changes: 1 addition & 2 deletions ogr/ogrsf_frmts/miramon/mm_gdal_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions ogr/ogrsf_frmts/miramon/mm_gdal_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 36 additions & 7 deletions ogr/ogrsf_frmts/miramon/mm_wrlayr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
1 change: 0 additions & 1 deletion ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 306655c

Please sign in to comment.