Skip to content

Commit

Permalink
Arrow/Parquet: fix compiler warnings on 32bit with clang -Wshorten-64…
Browse files Browse the repository at this point in the history
…-to-32
  • Loading branch information
rouault committed May 23, 2024
1 parent 12dab86 commit c64cb04
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
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 @@ -5315,7 +5331,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 @@ -5827,7 +5844,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

0 comments on commit c64cb04

Please sign in to comment.