Skip to content

Commit

Permalink
Fix -Werror=calloc-transposed-args with gcc 14
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed May 10, 2024
1 parent 6fe5012 commit 54c42b2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions dbfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1944,13 +1944,13 @@ int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, const int *panMap)
/* a simple malloc() would be enough, but calloc() helps clang static
* analyzer */
int *panFieldOffsetNew =
STATIC_CAST(int *, calloc(sizeof(int), psDBF->nFields));
STATIC_CAST(int *, calloc(psDBF->nFields, sizeof(int)));
int *panFieldSizeNew =
STATIC_CAST(int *, calloc(sizeof(int), psDBF->nFields));
STATIC_CAST(int *, calloc(psDBF->nFields, sizeof(int)));
int *panFieldDecimalsNew =
STATIC_CAST(int *, calloc(sizeof(int), psDBF->nFields));
STATIC_CAST(int *, calloc(psDBF->nFields, sizeof(int)));
char *pachFieldTypeNew =
STATIC_CAST(char *, calloc(sizeof(char), psDBF->nFields));
STATIC_CAST(char *, calloc(psDBF->nFields, sizeof(char)));
char *pszHeaderNew = STATIC_CAST(
char *, malloc(sizeof(char) * XBASE_FLDHDR_SZ * psDBF->nFields));

Expand Down
2 changes: 1 addition & 1 deletion sbnsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ SBNSearchHandle SBNOpenDiskTree(const char *pszSBNFilename,
/* Initialize the handle structure. */
/* -------------------------------------------------------------------- */
SBNSearchHandle hSBN =
STATIC_CAST(SBNSearchHandle, calloc(sizeof(struct SBNSearchInfo), 1));
STATIC_CAST(SBNSearchHandle, calloc(1, sizeof(struct SBNSearchInfo)));

if (psHooks == SHPLIB_NULLPTR)
SASetupDefaultHooks(&(hSBN->sHooks));
Expand Down
14 changes: 7 additions & 7 deletions shpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ SHPHandle SHPAPI_CALL SHPOpenLL(const char *pszLayer, const char *pszAccess,
/* -------------------------------------------------------------------- */
/* Initialize the info structure. */
/* -------------------------------------------------------------------- */
SHPHandle psSHP = STATIC_CAST(SHPHandle, calloc(sizeof(SHPInfo), 1));
SHPHandle psSHP = STATIC_CAST(SHPHandle, calloc(1, sizeof(SHPInfo)));

psSHP->bUpdated = FALSE;
memcpy(&(psSHP->sHooks), psHooks, sizeof(SAHooks));
Expand Down Expand Up @@ -1083,7 +1083,7 @@ SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType,
return SHPLIB_NULLPTR;
}

SHPHandle psSHP = STATIC_CAST(SHPHandle, calloc(sizeof(SHPInfo), 1));
SHPHandle psSHP = STATIC_CAST(SHPHandle, calloc(1, sizeof(SHPInfo)));

psSHP->bUpdated = FALSE;
memcpy(&(psSHP->sHooks), psHooks, sizeof(SAHooks));
Expand Down Expand Up @@ -1226,7 +1226,7 @@ SHPObject SHPAPI_CALL1(*)
psObject->nParts = MAX(1, nParts);

psObject->panPartStart =
STATIC_CAST(int *, calloc(sizeof(int), psObject->nParts));
STATIC_CAST(int *, calloc(psObject->nParts, sizeof(int)));
psObject->panPartType =
STATIC_CAST(int *, malloc(sizeof(int) * psObject->nParts));

Expand Down Expand Up @@ -1255,16 +1255,16 @@ SHPObject SHPAPI_CALL1(*)
const size_t nSize = sizeof(double) * nVertices;
psObject->padfX =
STATIC_CAST(double *, padfX ? malloc(nSize)
: calloc(sizeof(double), nVertices));
: calloc(nVertices, sizeof(double)));
psObject->padfY =
STATIC_CAST(double *, padfY ? malloc(nSize)
: calloc(sizeof(double), nVertices));
: calloc(nVertices, sizeof(double)));
psObject->padfZ = STATIC_CAST(
double *,
padfZ &&bHasZ ? malloc(nSize) : calloc(sizeof(double), nVertices));
padfZ &&bHasZ ? malloc(nSize) : calloc(nVertices, sizeof(double)));
psObject->padfM = STATIC_CAST(
double *,
padfM &&bHasM ? malloc(nSize) : calloc(sizeof(double), nVertices));
padfM &&bHasM ? malloc(nSize) : calloc(nVertices, sizeof(double)));
if (padfX != SHPLIB_NULLPTR)
memcpy(psObject->padfX, padfX, nSize);
if (padfY != SHPLIB_NULLPTR)
Expand Down
2 changes: 1 addition & 1 deletion shptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ SHPTreeDiskHandle SHPOpenDiskTree(const char *pszQIXFilename,
SHPTreeDiskHandle hDiskTree;

hDiskTree = STATIC_CAST(SHPTreeDiskHandle,
calloc(sizeof(struct SHPDiskTreeInfo), 1));
calloc(1, sizeof(struct SHPDiskTreeInfo)));

if (psHooks == SHPLIB_NULLPTR)
SASetupDefaultHooks(&(hDiskTree->sHooks));
Expand Down

0 comments on commit 54c42b2

Please sign in to comment.