From c94eaecfe8525480fa648607bd0e779e2038488b Mon Sep 17 00:00:00 2001 From: Thomas Beutlich Date: Tue, 21 May 2024 07:43:19 +0200 Subject: [PATCH] Fix issues reported by cppcheck 2.14.0 --- contrib/Shape_PointInPoly.cpp | 11 +++++------ contrib/dbfcat.c | 2 +- contrib/shpsort.c | 2 +- dbfdump.c | 2 +- dbfopen.c | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/contrib/Shape_PointInPoly.cpp b/contrib/Shape_PointInPoly.cpp index 24d8f01..4f3b568 100644 --- a/contrib/Shape_PointInPoly.cpp +++ b/contrib/Shape_PointInPoly.cpp @@ -72,8 +72,8 @@ loopDir LoopDirection(DPoint2d *vertices, int vertsize) DPoint2d CreatePointInPoly(SHPObject *psShape, int quality) { - int i, j, k, end, vert, pointpos; - double part, dx, xmin, xmax, ymin, ymax, y, x3, x4, y3, y4, len, maxlen = 0; + int i, j, k, end, vert; + double part, dx, xmin, xmax, ymin, ymax, x3, x4, y3, y4, len, maxlen = 0; DPoint2d *vertices; loopDir direction; IntersectPoint mp1, mp2, point1, point2, points[MAXINTERSECTIONPOINTS]; @@ -86,8 +86,8 @@ DPoint2d CreatePointInPoly(SHPObject *psShape, int quality) dx = xmax - xmin; for (i = 0; i < quality; i++) { - y = ymin + part * (i + 1); - pointpos = 0; + const double y = ymin + part * (i + 1); + int pointpos = 0; for (j = 0; j < psShape->nParts; j++) { if (j == psShape->nParts - 1) @@ -196,7 +196,6 @@ int main(int argc, char *argv[]) int i, nEntities, quality; SHPHandle hSHP; - SHPObject *psShape; DPoint2d pt; quality = atoi(argv[2]); hSHP = SHPOpen(argv[1], "rb"); @@ -205,7 +204,7 @@ int main(int argc, char *argv[]) printf("PointInPoly v1.0, by Marko Podgorsek\n----------------\n"); for (i = 0; i < nEntities; i++) { - psShape = SHPReadObject(hSHP, i); + SHPObject *psShape = SHPReadObject(hSHP, i); if (psShape->nSHPType == SHPT_POLYGON) { pt = CreatePointInPoly(psShape, quality); diff --git a/contrib/dbfcat.c b/contrib/dbfcat.c index da5de90..8c13d01 100644 --- a/contrib/dbfcat.c +++ b/contrib/dbfcat.c @@ -183,7 +183,7 @@ int main(int argc, char **argv) if (verbose) { const int ncRecords = DBFGetRecordCount(cDBF) - nRecords; - printf(" %u record%s appended\n\n", ncRecords, + printf(" %d record%s appended\n\n", ncRecords, ncRecords == 1 ? "" : "s"); } DBFClose(hDBF); diff --git a/contrib/shpsort.c b/contrib/shpsort.c index 7a5bc01..b4e90aa 100644 --- a/contrib/shpsort.c +++ b/contrib/shpsort.c @@ -185,7 +185,7 @@ static void copy_related(const char *inName, const char *outName, } #ifdef DEBUG -static void PrintDataStruct(struct DataStruct *data) +static void PrintDataStruct(const struct DataStruct *data) { for (int i = 0; i < nShapes; i++) { diff --git a/dbfdump.c b/dbfdump.c index d0fd1d7..471de2c 100644 --- a/dbfdump.c +++ b/dbfdump.c @@ -26,7 +26,7 @@ int main(int argc, char **argv) bool bHeader = false; bool bRaw = false; bool bMultiLine = false; - char *pszFilename = NULL; + const char *pszFilename = NULL; for (int i = 1; i < argc; i++) { diff --git a/dbfopen.c b/dbfopen.c index 4fc70b9..e0d7d88 100644 --- a/dbfopen.c +++ b/dbfopen.c @@ -481,7 +481,7 @@ DBFHandle SHPAPI_CALL DBFOpenLL(const char *pszFilename, const char *pszAccess, for (int iField = 0; iField < nFields; iField++) { - unsigned char *pabyFInfo = pabyBuf + iField * XBASE_FLDHDR_SZ; + const unsigned char *pabyFInfo = pabyBuf + iField * XBASE_FLDHDR_SZ; if (pabyFInfo[0] == HEADER_RECORD_TERMINATOR) { psDBF->nFields = iField;