diff --git a/.github/workflows/alpine_32bit/Dockerfile.ci b/.github/workflows/alpine_32bit/Dockerfile.ci index 4dee3a335fc0..bd85ef1320cb 100644 --- a/.github/workflows/alpine_32bit/Dockerfile.ci +++ b/.github/workflows/alpine_32bit/Dockerfile.ci @@ -9,6 +9,7 @@ RUN apk add \ brunsli-dev \ ccache \ cfitsio-dev \ + clang \ cmake \ curl-dev \ expat-dev \ diff --git a/.github/workflows/alpine_32bit/build.sh b/.github/workflows/alpine_32bit/build.sh index 77b1d9e93614..5424077ccf3e 100755 --- a/.github/workflows/alpine_32bit/build.sh +++ b/.github/workflows/alpine_32bit/build.sh @@ -4,6 +4,9 @@ set -e cmake ${GDAL_SOURCE_DIR:=..} \ -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_SHARED_LINKER_FLAGS="-lstdc++" \ -DUSE_CCACHE=ON \ -DCMAKE_INSTALL_PREFIX=/usr \ -DIconv_INCLUDE_DIR=/usr/include/gnu-libiconv \ diff --git a/.github/workflows/linux_build.yml b/.github/workflows/linux_build.yml index aec6b05ff504..ea2ee24b305d 100644 --- a/.github/workflows/linux_build.yml +++ b/.github/workflows/linux_build.yml @@ -71,7 +71,7 @@ jobs: build_script: build.sh os: ubuntu-22.04 - - name: Alpine, gcc 32-bit + - name: Alpine, clang 32-bit id: alpine_32bit container: alpine_32bit build_script: build.sh diff --git a/frmts/ceos2/sar_ceosdataset.cpp b/frmts/ceos2/sar_ceosdataset.cpp index f0b192cd03a5..545221838aa5 100644 --- a/frmts/ceos2/sar_ceosdataset.cpp +++ b/frmts/ceos2/sar_ceosdataset.cpp @@ -254,8 +254,10 @@ CPLErr SAR_CEOSRasterBand::IReadBlock(int /* nBlockXOff */, int nBlockYOff, /* -------------------------------------------------------------------- */ int nPixelsRead = 0; - GByte *pabyRecord = (GByte *)CPLMalloc( - static_cast(ImageDesc->BytesPerPixel) * nBlockXSize); + GByte *pabyRecord = + (GByte *)VSI_MALLOC2_VERBOSE(ImageDesc->BytesPerPixel, nBlockXSize); + if (!pabyRecord) + return CE_Failure; for (int iRecord = 0; iRecord < ImageDesc->RecordsPerLine; iRecord++) { @@ -268,8 +270,9 @@ CPLErr SAR_CEOSRasterBand::IReadBlock(int /* nBlockXOff */, int nBlockYOff, CPL_IGNORE_RET_VAL(VSIFSeekL(poGDS->fpImage, offset, SEEK_SET)); CPL_IGNORE_RET_VAL(VSIFReadL( - pabyRecord + nPixelsRead * ImageDesc->BytesPerPixel, 1, - static_cast(nPixelsToRead) * ImageDesc->BytesPerPixel, + pabyRecord + + static_cast(nPixelsRead) * ImageDesc->BytesPerPixel, + 1, static_cast(nPixelsToRead) * ImageDesc->BytesPerPixel, poGDS->fpImage)); nPixelsRead += nPixelsToRead; diff --git a/frmts/null/nulldataset.cpp b/frmts/null/nulldataset.cpp index 14fafc65ab41..da5828e8015d 100644 --- a/frmts/null/nulldataset.cpp +++ b/frmts/null/nulldataset.cpp @@ -164,7 +164,7 @@ CPLErr GDALNullRasterBand::IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, if (nPixelSpace == GDALGetDataTypeSizeBytes(eBufType) && nLineSpace == nPixelSpace * nBufXSize) { - memset(pData, 0, nLineSpace * nBufYSize); + memset(pData, 0, static_cast(nLineSpace) * nBufYSize); } else { diff --git a/ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp b/ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp index 31ab3688429f..ac5d7d96b256 100644 --- a/ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp +++ b/ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp @@ -683,8 +683,23 @@ inline std::unique_ptr OGRArrowLayer::BuildDomainFromBatch( eType = OFTInteger64; auto values = std::static_pointer_cast(dict); std::vector asValues; - asValues.reserve(values->length()); - for (int i = 0; i < values->length(); ++i) + if (values->length() > INT_MAX) + { + CPLError(CE_Failure, CPLE_OutOfMemory, + "BuildDomainFromBatch(): too many values"); + return nullptr; + } + try + { + asValues.reserve(static_cast(values->length())); + } + catch (const std::bad_alloc &) + { + CPLError(CE_Failure, CPLE_OutOfMemory, + "BuildDomainFromBatch(): out of memory"); + return nullptr; + } + for (int i = 0; i < static_cast(values->length()); ++i) { if (!values->IsNull(i)) { @@ -1345,7 +1360,8 @@ static CPLJSONArray GetListAsJSON(const ArrowType *array, if (values->IsNull(nIdxStart + k)) oArray.AddNull(); else - AddToArray(oArray, values.get(), nIdxStart + k); + AddToArray(oArray, values.get(), + static_cast(nIdxStart + k)); } return oArray; } @@ -1795,10 +1811,10 @@ static void ReadList(OGRFeature *poFeature, int i, int64_t nIdxInArray, case arrow::Type::MAP: case arrow::Type::STRUCT: { - poFeature->SetField(i, - GetListAsJSON(array, nIdxInArray) - .Format(CPLJSONObject::PrettyFormat::Plain) - .c_str()); + poFeature->SetField( + i, GetListAsJSON(array, static_cast(nIdxInArray)) + .Format(CPLJSONObject::PrettyFormat::Plain) + .c_str()); break; } @@ -2389,7 +2405,7 @@ inline OGRFeature *OGRArrowLayer::ReadFeature( const auto castArray = static_cast(array); poFeature->SetField( - i, GetMapAsJSON(castArray, nIdxInBatch) + i, GetMapAsJSON(castArray, static_cast(nIdxInBatch)) .Format(CPLJSONObject::PrettyFormat::Plain) .c_str()); break; @@ -5379,7 +5395,8 @@ OGRArrowLayer::GetArrowSchemaInternal(struct ArrowSchema *out_schema) const }; // cppcheck-suppress unreadVariable - std::vector fieldDesc(out_schema->n_children); + std::vector fieldDesc( + static_cast(out_schema->n_children)); for (size_t i = 0; i < m_anMapFieldIndexToArrowColumn.size(); i++) { const int nArrowCol = m_anMapFieldIndexToArrowColumn[i][0]; @@ -5895,7 +5912,7 @@ OGRArrowLayer::CreateWKBArrayFromWKTArray(const struct ArrowArray *sourceArray) const size_t nWKBSize = oTranslator.TranslateWKT( sourceBytes + sourceOffsets[i], - sourceOffsets[i + 1] - sourceOffsets[i], + static_cast(sourceOffsets[i + 1] - sourceOffsets[i]), sourceOffsets[i + 1] < sourceOffsets[nLength]); if (nWKBSize == static_cast(-1)) { diff --git a/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp b/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp index 17a8c0b3f6f2..bb0735fcb1db 100644 --- a/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp +++ b/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp @@ -2705,7 +2705,8 @@ inline bool OGRArrowWriterLayer::WriteArrowBatchInternal( bool bValidGeom = false; if (!pabyValidity || - TestBit(pabyValidity, iRow + psGeomArray->offset)) + TestBit(pabyValidity, + static_cast(iRow + psGeomArray->offset))) { const auto nLen = bUseOffsets32 ? static_cast(panOffsets32[iRow + 1] - diff --git a/ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp b/ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp index e87270dfdf0d..6811e6fb0b26 100644 --- a/ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp +++ b/ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp @@ -1702,12 +1702,12 @@ OGRErr OGRHanaTableLayer::AlterFieldDefn(int field, OGRFieldDefn *newFieldDefn, OGRFieldDefn *fieldDefn = featureDefn_->GetFieldDefn(field); - int64_t columnDescIdx = -1; + int columnDescIdx = -1; for (size_t i = 0; i < attrColumns_.size(); ++i) { if (EQUAL(attrColumns_[i].name.c_str(), fieldDefn->GetNameRef())) { - columnDescIdx = i; + columnDescIdx = static_cast(i); break; } } diff --git a/port/cpl_multiproc.cpp b/port/cpl_multiproc.cpp index 42d559905b8a..192c87d82d8f 100644 --- a/port/cpl_multiproc.cpp +++ b/port/cpl_multiproc.cpp @@ -1783,8 +1783,9 @@ CPLCondTimedWaitReason CPLCondTimedWait(CPLCond *hCond, CPLMutex *hMutex, gettimeofday(&tv, nullptr); ts.tv_sec = time(nullptr) + static_cast(dfWaitInSeconds); - ts.tv_nsec = tv.tv_usec * 1000 + static_cast(1000 * 1000 * 1000 * - fmod(dfWaitInSeconds, 1)); + ts.tv_nsec = + static_cast(tv.tv_usec) * 1000 + + static_cast(1000 * 1000 * 1000 * fmod(dfWaitInSeconds, 1)); ts.tv_sec += ts.tv_nsec / (1000 * 1000 * 1000); ts.tv_nsec %= (1000 * 1000 * 1000); int ret = pthread_cond_timedwait(pCond, pMutex, &ts);