Skip to content

Commit c69d113

Browse files
committed
const-correctness
Add "const" to a bunch of pointers that are not written to.
1 parent 77313de commit c69d113

File tree

8 files changed

+20
-19
lines changed

8 files changed

+20
-19
lines changed

mapbits.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ms_bitarray msAllocBitArray(int numbits)
5555
return(array);
5656
}
5757

58-
int msGetBit(ms_bitarray array, int index)
58+
int msGetBit(ms_const_bitarray array, int index)
5959
{
6060
array += index / MS_ARRAY_BIT;
6161
return (*array & (1 << (index % MS_ARRAY_BIT))) != 0; /* 0 or 1 */
@@ -68,7 +68,7 @@ int msGetBit(ms_bitarray array, int index)
6868
** If hits end of bitmap without finding set bit, will return -1.
6969
**
7070
*/
71-
int msGetNextBit(ms_bitarray array, int i, int size)
71+
int msGetNextBit(ms_const_bitarray array, int i, int size)
7272
{
7373

7474
register ms_uint32 b;

mapsearch.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int msRectIntersect( rectObj *a, const rectObj *b )
7777
/*
7878
** Returns MS_TRUE if rectangle a is contained in rectangle b
7979
*/
80-
int msRectContained(rectObj *a, rectObj *b)
80+
int msRectContained(const rectObj *a, const rectObj *b)
8181
{
8282
if(a->minx >= b->minx && a->maxx <= b->maxx)
8383
if(a->miny >= b->miny && a->maxy <= b->maxy)
@@ -96,7 +96,7 @@ void msMergeRect(rectObj *a, rectObj *b)
9696
a->maxy = MS_MAX(a->maxy, b->maxy);
9797
}
9898

99-
int msPointInRect(pointObj *p, rectObj *rect)
99+
int msPointInRect(const pointObj *p, const rectObj *rect)
100100
{
101101
if(p->x < rect->minx) return(MS_FALSE);
102102
if(p->x > rect->maxx) return(MS_FALSE);

mapserver.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ typedef struct face_element face_element;
121121

122122
/* ms_bitarray is used by the bit mask in mapbit.c */
123123
typedef ms_uint32 * ms_bitarray;
124+
typedef const ms_uint32 *ms_const_bitarray;
124125

125126
#include "maperror.h"
126127
#include "mapprimitive.h"
@@ -2079,9 +2080,9 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
20792080
MS_DLL_EXPORT double msInchesPerUnit(int units, double center_lat);
20802081
MS_DLL_EXPORT int msEmbedScalebar(mapObj *map, imageObj *img);
20812082

2082-
MS_DLL_EXPORT int msPointInRect(pointObj *p, rectObj *rect); /* in mapsearch.c */
2083+
MS_DLL_EXPORT int msPointInRect(const pointObj *p, const rectObj *rect); /* in mapsearch.c */
20832084
MS_DLL_EXPORT int msRectOverlap(const rectObj *a, const rectObj *b);
2084-
MS_DLL_EXPORT int msRectContained(rectObj *a, rectObj *b);
2085+
MS_DLL_EXPORT int msRectContained(const rectObj *a, const rectObj *b);
20852086
MS_DLL_EXPORT int msRectIntersect(rectObj *a, const rectObj *b);
20862087

20872088
MS_DLL_EXPORT void msRectToFormattedString(rectObj *rect, char *format,
@@ -2337,11 +2338,11 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
23372338

23382339
MS_DLL_EXPORT size_t msGetBitArraySize(int numbits); /* in mapbits.c */
23392340
MS_DLL_EXPORT ms_bitarray msAllocBitArray(int numbits);
2340-
MS_DLL_EXPORT int msGetBit(ms_bitarray array, int index);
2341+
MS_DLL_EXPORT int msGetBit(ms_const_bitarray array, int index);
23412342
MS_DLL_EXPORT void msSetBit(ms_bitarray array, int index, int value);
23422343
MS_DLL_EXPORT void msSetAllBits(ms_bitarray array, int index, int value);
23432344
MS_DLL_EXPORT void msFlipBit(ms_bitarray array, int index);
2344-
MS_DLL_EXPORT int msGetNextBit(ms_bitarray array, int index, int size);
2345+
MS_DLL_EXPORT int msGetNextBit(ms_const_bitarray array, int index, int size);
23452346

23462347
/* maplayer.c - layerObj api */
23472348

mapshape.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ int msSHPReadBounds( SHPHandle psSHP, int hEntity, rectObj *padBounds)
16961696
return MS_SUCCESS;
16971697
}
16981698

1699-
int msShapefileOpen(shapefileObj *shpfile, char *mode, char *filename, int log_failures)
1699+
int msShapefileOpen(shapefileObj *shpfile, const char *mode, const char *filename, int log_failures)
17001700
{
17011701
int i;
17021702
char *dbfFilename;

mapshape.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ extern "C" {
182182
} msTiledSHPLayerInfo;
183183

184184
/* shapefileObj function prototypes */
185-
MS_DLL_EXPORT int msShapefileOpen(shapefileObj *shpfile, char *mode, char *filename, int log_failures);
185+
MS_DLL_EXPORT int msShapefileOpen(shapefileObj *shpfile, const char *mode, const char *filename, int log_failures);
186186
MS_DLL_EXPORT int msShapefileCreate(shapefileObj *shpfile, char *filename, int type);
187187
MS_DLL_EXPORT void msShapefileClose(shapefileObj *shpfile);
188188
MS_DLL_EXPORT int msShapefileWhichShapes(shapefileObj *shpfile, rectObj rect, int debug);

maptree.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static void treeCollectShapeIds(treeNodeObj *node, rectObj aoi, ms_bitarray stat
399399
}
400400
}
401401

402-
ms_bitarray msSearchTree(treeObj *tree, rectObj aoi)
402+
ms_bitarray msSearchTree(const treeObj *tree, rectObj aoi)
403403
{
404404
ms_bitarray status=NULL;
405405

@@ -511,7 +511,7 @@ static void searchDiskTreeNode(SHPTreeHandle disktree, rectObj aoi, ms_bitarray
511511
return;
512512
}
513513

514-
ms_bitarray msSearchDiskTree(char *filename, rectObj aoi, int debug)
514+
ms_bitarray msSearchDiskTree(const char *filename, rectObj aoi, int debug)
515515
{
516516
SHPTreeHandle disktree;
517517
ms_bitarray status=NULL;

maptree.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ extern "C" {
8484
MS_DLL_EXPORT void msTreeTrim(treeObj *tree);
8585
MS_DLL_EXPORT void msDestroyTree(treeObj *tree);
8686

87-
MS_DLL_EXPORT ms_bitarray msSearchTree(treeObj *tree, rectObj aoi);
88-
MS_DLL_EXPORT ms_bitarray msSearchDiskTree(char *filename, rectObj aoi, int debug);
87+
MS_DLL_EXPORT ms_bitarray msSearchTree(const treeObj *tree, rectObj aoi);
88+
MS_DLL_EXPORT ms_bitarray msSearchDiskTree(const char *filename, rectObj aoi, int debug);
8989

9090
MS_DLL_EXPORT treeObj *msReadTree(char *filename, int debug);
9191
MS_DLL_EXPORT int msWriteTree(treeObj *tree, char *filename, int LSB_order);

mapxbase.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,13 @@ int DBFIsValueNULL( const char* pszValue, char type )
497497
/* */
498498
/* Read one of the attribute fields of a record. */
499499
/************************************************************************/
500-
static char *msDBFReadAttribute(DBFHandle psDBF, int hEntity, int iField )
500+
static const char *msDBFReadAttribute(DBFHandle psDBF, int hEntity, int iField )
501501

502502
{
503503
int i;
504504
unsigned int nRecordOffset;
505-
uchar *pabyRec;
506-
char *pReturnField = NULL;
505+
const uchar *pabyRec;
506+
const char *pReturnField = NULL;
507507

508508
/* -------------------------------------------------------------------- */
509509
/* Is the request valid? */
@@ -532,7 +532,7 @@ static char *msDBFReadAttribute(DBFHandle psDBF, int hEntity, int iField )
532532
psDBF->nCurrentRecord = hEntity;
533533
}
534534

535-
pabyRec = (uchar *) psDBF->pszCurrentRecord;
535+
pabyRec = (const uchar *) psDBF->pszCurrentRecord;
536536
/* DEBUG */
537537
/* printf("CurrentRecord(%c):%s\n", psDBF->pachFieldType[iField], pabyRec); */
538538

@@ -547,7 +547,7 @@ static char *msDBFReadAttribute(DBFHandle psDBF, int hEntity, int iField )
547547
/* -------------------------------------------------------------------- */
548548
/* Extract the requested field. */
549549
/* -------------------------------------------------------------------- */
550-
strncpy( psDBF->pszStringField,(char *) pabyRec+psDBF->panFieldOffset[iField], psDBF->panFieldSize[iField] );
550+
strncpy( psDBF->pszStringField,(const char *) pabyRec+psDBF->panFieldOffset[iField], psDBF->panFieldSize[iField] );
551551
psDBF->pszStringField[psDBF->panFieldSize[iField]] = '\0';
552552

553553
/*

0 commit comments

Comments
 (0)