Skip to content

Commit

Permalink
Merge pull request #9992 from rouault/arrow_32bit_warnings
Browse files Browse the repository at this point in the history
Fix clang -Wshorten-64-to-32 warnings on 32 bit builds
  • Loading branch information
rouault committed May 29, 2024
2 parents 1118039 + 7051a9e commit 92df169
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/alpine_32bit/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN apk add \
brunsli-dev \
ccache \
cfitsio-dev \
clang \
cmake \
curl-dev \
expat-dev \
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/alpine_32bit/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions frmts/ceos2/sar_ceosdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ CPLErr SAR_CEOSRasterBand::IReadBlock(int /* nBlockXOff */, int nBlockYOff,
/* -------------------------------------------------------------------- */
int nPixelsRead = 0;

GByte *pabyRecord = (GByte *)CPLMalloc(
static_cast<size_t>(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++)
{
Expand All @@ -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<vsi_l_offset>(nPixelsToRead) * ImageDesc->BytesPerPixel,
pabyRecord +
static_cast<size_t>(nPixelsRead) * ImageDesc->BytesPerPixel,
1, static_cast<size_t>(nPixelsToRead) * ImageDesc->BytesPerPixel,
poGDS->fpImage));

nPixelsRead += nPixelsToRead;
Expand Down
2 changes: 1 addition & 1 deletion frmts/null/nulldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(nLineSpace) * nBufYSize);
}
else
{
Expand Down
37 changes: 27 additions & 10 deletions ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,23 @@ inline std::unique_ptr<OGRFieldDomain> OGRArrowLayer::BuildDomainFromBatch(
eType = OFTInteger64;
auto values = std::static_pointer_cast<arrow::StringArray>(dict);
std::vector<OGRCodedValue> 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<size_t>(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<int>(values->length()); ++i)
{
if (!values->IsNull(i))
{
Expand Down Expand Up @@ -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<size_t>(nIdxStart + k));
}
return oArray;
}
Expand Down Expand Up @@ -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<size_t>(nIdxInArray))
.Format(CPLJSONObject::PrettyFormat::Plain)
.c_str());
break;
}

Expand Down Expand Up @@ -2389,7 +2405,7 @@ inline OGRFeature *OGRArrowLayer::ReadFeature(
const auto castArray =
static_cast<const arrow::MapArray *>(array);
poFeature->SetField(
i, GetMapAsJSON(castArray, nIdxInBatch)
i, GetMapAsJSON(castArray, static_cast<size_t>(nIdxInBatch))
.Format(CPLJSONObject::PrettyFormat::Plain)
.c_str());
break;
Expand Down Expand Up @@ -5379,7 +5395,8 @@ OGRArrowLayer::GetArrowSchemaInternal(struct ArrowSchema *out_schema) const
};

// cppcheck-suppress unreadVariable
std::vector<FieldDesc> fieldDesc(out_schema->n_children);
std::vector<FieldDesc> fieldDesc(
static_cast<size_t>(out_schema->n_children));
for (size_t i = 0; i < m_anMapFieldIndexToArrowColumn.size(); i++)
{
const int nArrowCol = m_anMapFieldIndexToArrowColumn[i][0];
Expand Down Expand Up @@ -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<size_t>(sourceOffsets[i + 1] - sourceOffsets[i]),
sourceOffsets[i + 1] < sourceOffsets[nLength]);
if (nWKBSize == static_cast<size_t>(-1))
{
Expand Down
3 changes: 2 additions & 1 deletion ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,8 @@ inline bool OGRArrowWriterLayer::WriteArrowBatchInternal(
bool bValidGeom = false;

if (!pabyValidity ||
TestBit(pabyValidity, iRow + psGeomArray->offset))
TestBit(pabyValidity,
static_cast<size_t>(iRow + psGeomArray->offset)))
{
const auto nLen =
bUseOffsets32 ? static_cast<size_t>(panOffsets32[iRow + 1] -
Expand Down
4 changes: 2 additions & 2 deletions ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(i);
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions port/cpl_multiproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,8 +1783,9 @@ CPLCondTimedWaitReason CPLCondTimedWait(CPLCond *hCond, CPLMutex *hMutex,

gettimeofday(&tv, nullptr);
ts.tv_sec = time(nullptr) + static_cast<int>(dfWaitInSeconds);
ts.tv_nsec = tv.tv_usec * 1000 + static_cast<int>(1000 * 1000 * 1000 *
fmod(dfWaitInSeconds, 1));
ts.tv_nsec =
static_cast<int>(tv.tv_usec) * 1000 +
static_cast<int>(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);
Expand Down

0 comments on commit 92df169

Please sign in to comment.