Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix const-correctness #69

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions dbfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ static void DBFWriteHeader(DBFHandle psDBF)
psDBF->bNoHeader = FALSE;

/* -------------------------------------------------------------------- */
/* Initialize the file header information. */
/* Initialize the file header information. */
/* -------------------------------------------------------------------- */
abyHeader[0] = 0x03; /* memo field? - just copying */
abyHeader[0] = 0x03; /* memo field? - just copying */

/* write out update date */
abyHeader[1] = STATIC_CAST(unsigned char, psDBF->nUpdateYearSince1900);
Expand All @@ -120,7 +120,7 @@ static void DBFWriteHeader(DBFHandle psDBF)

/* -------------------------------------------------------------------- */
/* Write the initial 32 byte file header, and all the field */
/* descriptions. */
/* descriptions. */
/* -------------------------------------------------------------------- */
psDBF->sHooks.FSeek(psDBF->fp, 0, 0);
psDBF->sHooks.FWrite(abyHeader, XBASE_FILEHDR_SZ, 1, psDBF->fp);
Expand Down Expand Up @@ -361,8 +361,8 @@ DBFHandle SHPAPI_CALL DBFOpenLL(const char *pszFilename, const char *pszAccess,
pszAccess = "rb+";

/* -------------------------------------------------------------------- */
/* Compute the base (layer) name. If there is any extension */
/* on the passed in filename we will strip it off. */
/* Compute the base (layer) name. If there is any extension */
/* on the passed in filename we will strip it off. */
/* -------------------------------------------------------------------- */
const int nLenWithoutExtension = DBFGetLenWithoutExtension(pszFilename);
char *pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5));
Expand Down Expand Up @@ -515,8 +515,8 @@ DBFHandle SHPAPI_CALL DBFOpenLL(const char *pszFilename, const char *pszAccess,
** string fields, but in other cases (such as bug 1202) the decimals field
** just seems to indicate some sort of preferred formatting, not very
** wide fields. So I have disabled this code. FrankW.
psDBF->panFieldSize[iField] = pabyFInfo[16] + pabyFInfo[17]*256;
psDBF->panFieldDecimals[iField] = 0;
psDBF->panFieldSize[iField] = pabyFInfo[16] + pabyFInfo[17]*256;
psDBF->panFieldDecimals[iField] = 0;
*/
}

Expand Down Expand Up @@ -562,8 +562,8 @@ void SHPAPI_CALL DBFClose(DBFHandle psDBF)
CPL_IGNORE_RET_VAL_INT(DBFFlushRecord(psDBF));

/* -------------------------------------------------------------------- */
/* Update last access date, and number of records if we have */
/* write access. */
/* Update last access date, and number of records if we have */
/* write access. */
/* -------------------------------------------------------------------- */
if (psDBF->bUpdated)
DBFUpdateHeader(psDBF);
Expand Down Expand Up @@ -629,8 +629,8 @@ DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename,
const SAHooks *psHooks)
{
/* -------------------------------------------------------------------- */
/* Compute the base (layer) name. If there is any extension */
/* on the passed in filename we will strip it off. */
/* Compute the base (layer) name. If there is any extension */
/* on the passed in filename we will strip it off. */
/* -------------------------------------------------------------------- */
const int nLenWithoutExtension = DBFGetLenWithoutExtension(pszFilename);
char *pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5));
Expand Down Expand Up @@ -686,7 +686,7 @@ DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename,
free(pszFullname);

/* -------------------------------------------------------------------- */
/* Create the info structure. */
/* Create the info structure. */
/* -------------------------------------------------------------------- */
DBFHandle psDBF = STATIC_CAST(DBFHandle, calloc(1, sizeof(DBFInfo)));

Expand Down Expand Up @@ -965,13 +965,13 @@ static void *DBFReadAttribute(DBFHandle psDBF, int hEntity, int iField,
return SHPLIB_NULLPTR;

/* -------------------------------------------------------------------- */
/* Have we read the record? */
/* Have we read the record? */
/* -------------------------------------------------------------------- */
if (!DBFLoadRecord(psDBF, hEntity))
return SHPLIB_NULLPTR;

unsigned char *pabyRec =
REINTERPRET_CAST(unsigned char *, psDBF->pszCurrentRecord);
const unsigned char *pabyRec =
REINTERPRET_CAST(const unsigned char *, psDBF->pszCurrentRecord);

/* -------------------------------------------------------------------- */
/* Ensure we have room to extract the target field. */
Expand All @@ -988,7 +988,7 @@ static void *DBFReadAttribute(DBFHandle psDBF, int hEntity, int iField,
}

/* -------------------------------------------------------------------- */
/* Extract the requested field. */
/* Extract the requested field. */
/* -------------------------------------------------------------------- */
memcpy(psDBF->pszWorkField,
REINTERPRET_CAST(const char *, pabyRec) +
Expand Down Expand Up @@ -1246,15 +1246,15 @@ DBFFieldType SHPAPI_CALL DBFGetFieldInfo(DBFHandle psDBF, int iField,

/************************************************************************/
/* DBFWriteAttribute() */
/* */
/* Write an attribute record to the file. */
/* */
/* Write an attribute record to the file. */
/************************************************************************/

static bool DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField,
void *pValue)
{
/* -------------------------------------------------------------------- */
/* Is this a valid record? */
/* Is this a valid record? */
/* -------------------------------------------------------------------- */
if (hEntity < 0 || hEntity > psDBF->nRecords)
return false;
Expand Down Expand Up @@ -1381,10 +1381,10 @@ static bool DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField,
/************************************************************************/

int SHPAPI_CALL DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity,
int iField, void *pValue)
int iField, const void *pValue)
{
/* -------------------------------------------------------------------- */
/* Is this a valid record? */
/* Is this a valid record? */
/* -------------------------------------------------------------------- */
if (hEntity < 0 || hEntity > psDBF->nRecords)
return (FALSE);
Expand Down Expand Up @@ -1512,14 +1512,15 @@ int SHPAPI_CALL DBFWriteLogicalAttribute(DBFHandle psDBF, int iRecord,

/************************************************************************/
/* DBFWriteTuple() */
/* */
/* Write an attribute record to the file. */
/* */
/* Write an attribute record to the file. */
/************************************************************************/

int SHPAPI_CALL DBFWriteTuple(DBFHandle psDBF, int hEntity, void *pRawTuple)
int SHPAPI_CALL DBFWriteTuple(DBFHandle psDBF, int hEntity,
const void *pRawTuple)
{
/* -------------------------------------------------------------------- */
/* Is this a valid record? */
/* Is this a valid record? */
/* -------------------------------------------------------------------- */
if (hEntity < 0 || hEntity > psDBF->nRecords)
return (FALSE);
Expand Down Expand Up @@ -1580,7 +1581,7 @@ const char SHPAPI_CALL1(*) DBFReadTuple(DBFHandle psDBF, int hEntity)
}

/************************************************************************/
/* DBFCloneEmpty() */
/* DBFCloneEmpty() */
/* */
/* Read one of the attribute fields of a record. */
/************************************************************************/
Expand Down Expand Up @@ -1690,7 +1691,7 @@ int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape)
return TRUE;

/* -------------------------------------------------------------------- */
/* Have we read the record? */
/* Have we read the record? */
/* -------------------------------------------------------------------- */
if (!DBFLoadRecord(psDBF, iShape))
return FALSE;
Expand Down Expand Up @@ -1885,7 +1886,7 @@ int SHPAPI_CALL DBFDeleteField(DBFHandle psDBF, int iField)
/* code of DBFReorderFields. */
/************************************************************************/

int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, int *panMap)
int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, const int *panMap)
{
if (psDBF->nFields == 0)
return TRUE;
Expand Down
3 changes: 2 additions & 1 deletion safileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ static SAOffset SADFRead(void *p, SAOffset size, SAOffset nmemb, SAFile file)
return (SAOffset)fread(p, (size_t)size, (size_t)nmemb, (FILE *)file);
}

static SAOffset SADFWrite(void *p, SAOffset size, SAOffset nmemb, SAFile file)
static SAOffset SADFWrite(const void *p, SAOffset size, SAOffset nmemb,
SAFile file)
{
return (SAOffset)fwrite(p, (size_t)size, (size_t)nmemb, (FILE *)file);
}
Expand Down
4 changes: 2 additions & 2 deletions sbnsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ static int compare_ints(const void *a, const void *b)
/* SBNSearchDiskTree() */
/************************************************************************/

int *SBNSearchDiskTree(SBNSearchHandle hSBN, double *padfBoundsMin,
double *padfBoundsMax, int *pnShapeCount)
int *SBNSearchDiskTree(SBNSearchHandle hSBN, const double *padfBoundsMin,
const double *padfBoundsMax, int *pnShapeCount)
{
*pnShapeCount = 0;

Expand Down
21 changes: 11 additions & 10 deletions shapefil.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern "C"
/* various calling conventions on the Shapelib API. */
/* */
/* To force __stdcall conventions (needed to call Shapelib */
/* from Visual Basic and/or Dephi I believe) the makefile could */
/* from Visual Basic and/or Delphi I believe) the makefile could */
/* be modified to define: */
/* */
/* /DSHPAPI_CALL=__stdcall */
Expand Down Expand Up @@ -121,7 +121,8 @@ extern "C"
{
SAFile (*FOpen)(const char *filename, const char *access);
SAOffset (*FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file);
SAOffset (*FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file);
SAOffset (*FWrite)(const void *p, SAOffset size, SAOffset nmemb,
SAFile file);
SAOffset (*FSeek)(SAFile file, SAOffset offset, int whence);
SAOffset (*FTell)(SAFile file);
int (*FFlush)(SAFile file);
Expand Down Expand Up @@ -333,7 +334,7 @@ extern "C"

SHPTree SHPAPI_CALL1(*)
SHPCreateTree(SHPHandle hSHP, int nDimension, int nMaxDepth,
double *padfBoundsMin, double *padfBoundsMax);
const double *padfBoundsMin, const double *padfBoundsMax);
void SHPAPI_CALL SHPDestroyTree(SHPTree *hTree);

int SHPAPI_CALL SHPWriteTree(SHPTree *hTree, const char *pszFilename);
Expand All @@ -346,8 +347,8 @@ extern "C"
int SHPAPI_CALL1(*)
SHPTreeFindLikelyShapes(SHPTree *hTree, double *padfBoundsMin,
double *padfBoundsMax, int *);
int SHPAPI_CALL SHPCheckBoundsOverlap(double *, double *, double *,
double *, int);
int SHPAPI_CALL SHPCheckBoundsOverlap(const double *, const double *,
const double *, const double *, int);

int SHPAPI_CALL1(*)
SHPSearchDiskTree(FILE *fp, double *padfBoundsMin,
Expand Down Expand Up @@ -379,8 +380,8 @@ extern "C"
void SHPAPI_CALL SBNCloseDiskTree(SBNSearchHandle hSBN);

int SHPAPI_CALL1(*)
SBNSearchDiskTree(SBNSearchHandle hSBN, double *padfBoundsMin,
double *padfBoundsMax, int *pnShapeCount);
SBNSearchDiskTree(SBNSearchHandle hSBN, const double *padfBoundsMin,
const double *padfBoundsMax, int *pnShapeCount);

int SHPAPI_CALL1(*)
SBNSearchDiskTreeInteger(SBNSearchHandle hSBN, int bMinX, int bMinY,
Expand Down Expand Up @@ -483,7 +484,7 @@ extern "C"

int SHPAPI_CALL DBFDeleteField(DBFHandle hDBF, int iField);

int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, int *panMap);
int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, const int *panMap);

int SHPAPI_CALL DBFAlterFieldDefn(DBFHandle psDBF, int iField,
const char *pszFieldName, char chType,
Expand Down Expand Up @@ -519,10 +520,10 @@ extern "C"
int iField,
const char lFieldValue);
int SHPAPI_CALL DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity,
int iField, void *pValue);
int iField, const void *pValue);
const char SHPAPI_CALL1(*) DBFReadTuple(DBFHandle psDBF, int hEntity);
int SHPAPI_CALL DBFWriteTuple(DBFHandle psDBF, int hEntity,
void *pRawTuple);
const void *pRawTuple);

int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape);
int SHPAPI_CALL DBFMarkRecordDeleted(DBFHandle psDBF, int iShape,
Expand Down
Loading