diff --git a/alg/internal_libqhull/poly_r.c b/alg/internal_libqhull/poly_r.c index b7e09b54fc8d..4a034131f201 100644 --- a/alg/internal_libqhull/poly_r.c +++ b/alg/internal_libqhull/poly_r.c @@ -1180,9 +1180,9 @@ int qh_pointid(qhT *qh, pointT *point) { /* coverity[divide_arg] */ id= offset / qh->hull_dim; } else { - id = qh_setindex(qh->other_points, point); - if (id >= 0) { - id += qh->num_points; + const int idx = qh_setindex(qh->other_points, point); + if (idx >= 0) { + id = (ptr_intT)idx + qh->num_points; } else { return qh_IDunknown; } diff --git a/autotest/ogr/ogr_geom.py b/autotest/ogr/ogr_geom.py index 53274e595e64..94e8b65314e9 100755 --- a/autotest/ogr/ogr_geom.py +++ b/autotest/ogr/ogr_geom.py @@ -930,21 +930,21 @@ def test_ogr_geom_segmentize_issue_1341(): geom = ogr.CreateGeometryFromWkt("LINESTRING(0 0,10 0)") geom.Segmentize(0.399999999999) - assert geom.ExportToWkt() == expected_geom + ogrtest.check_feature_geometry(geom, expected_geom) geom.Segmentize(0.399999999999) - assert geom.ExportToWkt() == expected_geom + ogrtest.check_feature_geometry(geom, expected_geom) geom = ogr.CreateGeometryFromWkt("LINESTRING(0 0,10 0)") geom.Segmentize(0.4) - assert geom.ExportToWkt() == expected_geom + ogrtest.check_feature_geometry(geom, expected_geom) geom.Segmentize(0.4) - assert geom.ExportToWkt() == expected_geom + ogrtest.check_feature_geometry(geom, expected_geom) geom = ogr.CreateGeometryFromWkt("LINESTRING(0 0,10 0)") geom.Segmentize(0.400000000001) - assert geom.ExportToWkt() == expected_geom + ogrtest.check_feature_geometry(geom, expected_geom) geom.Segmentize(0.400000000001) - assert geom.ExportToWkt() == expected_geom + ogrtest.check_feature_geometry(geom, expected_geom) ############################################################################### diff --git a/frmts/jpeg/jpgdataset.cpp b/frmts/jpeg/jpgdataset.cpp index a8425a65b39a..c49235ed0962 100644 --- a/frmts/jpeg/jpgdataset.cpp +++ b/frmts/jpeg/jpgdataset.cpp @@ -3331,29 +3331,27 @@ void JPGDatasetCommon::CheckForMask() GByte abyEOD[2] = {0, 0}; - if (nImageSize < nFileSize / 2 || nImageSize > nFileSize - 4) - goto end; - - // If that seems okay, seek back, and verify that just preceding - // the bitmask is an apparent end-of-jpeg-data marker. - VSIFSeekL(m_fpImage, nImageSize - 2, SEEK_SET); - VSIFReadL(abyEOD, 2, 1, m_fpImage); - if (abyEOD[0] != 0xff || abyEOD[1] != 0xd9) - goto end; + if (nImageSize >= 2 && nImageSize >= nFileSize / 2 && + nImageSize <= nFileSize - 4) + { + // If that seems okay, seek back, and verify that just preceding + // the bitmask is an apparent end-of-jpeg-data marker. + VSIFSeekL(m_fpImage, nImageSize - 2, SEEK_SET); + VSIFReadL(abyEOD, 2, 1, m_fpImage); + if (abyEOD[0] == 0xff && abyEOD[1] == 0xd9) + { + // We seem to have a mask. Read it in. + nCMaskSize = static_cast(nFileSize - nImageSize - 4); + pabyCMask = static_cast(VSI_MALLOC_VERBOSE(nCMaskSize)); + if (pabyCMask) + { + VSIFReadL(pabyCMask, nCMaskSize, 1, m_fpImage); - // We seem to have a mask. Read it in. - nCMaskSize = static_cast(nFileSize - nImageSize - 4); - pabyCMask = static_cast(VSI_MALLOC_VERBOSE(nCMaskSize)); - if (pabyCMask == nullptr) - { - goto end; + CPLDebug("JPEG", "Got %d byte compressed bitmask.", nCMaskSize); + } + } } - VSIFReadL(pabyCMask, nCMaskSize, 1, m_fpImage); - - CPLDebug("JPEG", "Got %d byte compressed bitmask.", nCMaskSize); - // TODO(schwehr): Refactor to not use goto. -end: VSIFSeekL(m_fpImage, nCurOffset, SEEK_SET); } diff --git a/ogr/ogrlinestring.cpp b/ogr/ogrlinestring.cpp index 929b570901e0..1fb68d0c9894 100644 --- a/ogr/ogrlinestring.cpp +++ b/ogr/ogrlinestring.cpp @@ -2756,15 +2756,17 @@ bool OGRSimpleCurve::segmentize(double dfMaxLength) sqrt(dfSquareDist / dfSquareMaxLength) - REL_EPSILON_ROUND); const int nIntermediatePoints = DoubleToIntClamp(dfIntermediatePoints); + const double dfRatioX = + dfX / (static_cast(nIntermediatePoints) + 1); + const double dfRatioY = + dfY / (static_cast(nIntermediatePoints) + 1); for (int j = 1; j <= nIntermediatePoints; j++) { // coverity[overflow_const] const int newI = nNewPointCount + j - 1; - paoNewPoints[newI].x = - paoPoints[i].x + j * dfX / (nIntermediatePoints + 1); - paoNewPoints[newI].y = - paoPoints[i].y + j * dfY / (nIntermediatePoints + 1); + paoNewPoints[newI].x = paoPoints[i].x + j * dfRatioX; + paoNewPoints[newI].y = paoPoints[i].y + j * dfRatioY; if (padfZ != nullptr) { // No interpolation. diff --git a/ogr/ogrsf_frmts/vfk/vfkreadersqlite.cpp b/ogr/ogrsf_frmts/vfk/vfkreadersqlite.cpp index 687637754783..5d8ee5e81c15 100644 --- a/ogr/ogrsf_frmts/vfk/vfkreadersqlite.cpp +++ b/ogr/ogrsf_frmts/vfk/vfkreadersqlite.cpp @@ -442,24 +442,29 @@ int64_t VFKReaderSQLite::ReadDataRecords(IVFKDataBlock *poDataBlock) StoreInfo2DB(); /* Insert VFK data records into DB */ - nDataRecords += VFKReader::ReadDataRecords(poDataBlock); - - /* update VFK_DB_TABLE table */ - poDataBlockCurrent = nullptr; - for (int iDataBlock = 0; iDataBlock < GetDataBlockCount(); iDataBlock++) + const int64_t nExtraRecords = VFKReader::ReadDataRecords(poDataBlock); + if (nExtraRecords >= 0) { - poDataBlockCurrent = GetDataBlock(iDataBlock); + nDataRecords += nExtraRecords; - if (poDataBlock && poDataBlock != poDataBlockCurrent) - continue; + /* update VFK_DB_TABLE table */ + poDataBlockCurrent = nullptr; + for (int iDataBlock = 0; iDataBlock < GetDataBlockCount(); + iDataBlock++) + { + poDataBlockCurrent = GetDataBlock(iDataBlock); - /* update number of records in metadata table */ - osSQL.Printf("UPDATE %s SET num_records = %d WHERE " - "table_name = '%s'", - VFK_DB_TABLE, poDataBlockCurrent->GetRecordCount(), - poDataBlockCurrent->GetName()); + if (poDataBlock && poDataBlock != poDataBlockCurrent) + continue; - ExecuteSQL(osSQL); + /* update number of records in metadata table */ + osSQL.Printf("UPDATE %s SET num_records = %d WHERE " + "table_name = '%s'", + VFK_DB_TABLE, poDataBlockCurrent->GetRecordCount(), + poDataBlockCurrent->GetName()); + + ExecuteSQL(osSQL); + } } /* create indices if not exist */ diff --git a/port/cpl_md5.cpp b/port/cpl_md5.cpp index 4fc85cafb8cf..63b8e34856c3 100644 --- a/port/cpl_md5.cpp +++ b/port/cpl_md5.cpp @@ -85,8 +85,9 @@ void CPLMD5Update(struct CPLMD5Context *context, const void *buf, size_t len) // Update bitcount GUInt32 t = context->bits[0]; // coverity[overflow_const] - if ((context->bits[0] = - (t + (static_cast(len) << 3)) & 0xffffffff) < t) + const GUInt32 lenShifted = static_cast(len) << 3U; + context->bits[0] = (t + lenShifted) & 0xffffffff; + if (context->bits[0] < t) context->bits[1]++; /* Carry from low to high */ context->bits[1] += static_cast(len >> 29); diff --git a/port/cpl_path.cpp b/port/cpl_path.cpp index 0ad0d286a24f..3d98a668adab 100644 --- a/port/cpl_path.cpp +++ b/port/cpl_path.cpp @@ -606,6 +606,7 @@ const char *CPLFormFilename(const char *pszPath, const char *pszBasename, if (nLenPath >= static_cast(CPL_PATH_BUF_SIZE)) return CPLStaticBufferTooSmall(pszStaticResult); + // coverity[overrun-buffer-arg] memcpy(pszStaticResult, pszPath, nLenPath); pszStaticResult[nLenPath] = 0; diff --git a/port/cpl_spawn.cpp b/port/cpl_spawn.cpp index 31dc0341fd73..d3197a970bb4 100644 --- a/port/cpl_spawn.cpp +++ b/port/cpl_spawn.cpp @@ -458,7 +458,7 @@ int CPLPipeRead(CPL_FILE_HANDLE fin, void *data, int length) { while (true) { - const auto n = read(fin, pabyData, nRemain); + const ssize_t n = read(fin, pabyData, nRemain); if (n < 0) { if (errno == EINTR) @@ -499,7 +499,7 @@ int CPLPipeWrite(CPL_FILE_HANDLE fout, const void *data, int length) { while (true) { - const auto n = write(fout, pabyData, nRemain); + const ssize_t n = write(fout, pabyData, nRemain); if (n < 0) { if (errno == EINTR) diff --git a/port/cpl_worker_thread_pool.cpp b/port/cpl_worker_thread_pool.cpp index 387ad7bbba43..da1c69c3f1b6 100644 --- a/port/cpl_worker_thread_pool.cpp +++ b/port/cpl_worker_thread_pool.cpp @@ -503,6 +503,7 @@ CPLWorkerThreadPool::GetNextJob(CPLWorkerThread *psWorkerThread) std::unique_lock oGuardThisThread(psWorkerThread->m_mutex); // coverity[uninit_use_in_call] oGuard.unlock(); + // coverity[wait_not_in_locked_loop] psWorkerThread->m_cv.wait(oGuardThisThread); } }