Fix compilation error due to 64-bit integer narrowing to size_t (#5250)

This commit is contained in:
Philip Hyunsu Cho 2020-01-30 21:32:15 -08:00 committed by GitHub
parent 472ded549d
commit adc795929a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -311,7 +311,7 @@ XGB_DLL int XGDMatrixSliceDMatrixEx(DMatrixHandle handle,
DMatrix* dmat = static_cast<std::shared_ptr<DMatrix>*>(handle)->get(); DMatrix* dmat = static_cast<std::shared_ptr<DMatrix>*>(handle)->get();
CHECK(dynamic_cast<data::SimpleDMatrix*>(dmat)) CHECK(dynamic_cast<data::SimpleDMatrix*>(dmat))
<< "Slice only supported for SimpleDMatrix currently."; << "Slice only supported for SimpleDMatrix currently.";
data::DMatrixSliceAdapter adapter(dmat, {idxset, len}); data::DMatrixSliceAdapter adapter(dmat, {idxset, static_cast<size_t>(len)});
*out = new std::shared_ptr<DMatrix>( *out = new std::shared_ptr<DMatrix>(
DMatrix::Create(&adapter, std::numeric_limits<float>::quiet_NaN(), 1)); DMatrix::Create(&adapter, std::numeric_limits<float>::quiet_NaN(), 1));
API_END(); API_END();

View File

@ -670,9 +670,10 @@ class LearnerImpl : public Learner {
for more details about differences between saving model and serializing. for more details about differences between saving model and serializing.
)doc"; )doc";
int64_t json_offset {-1}; int64_t sz {-1};
CHECK_EQ(fp.Read(&json_offset, sizeof(json_offset)), sizeof(json_offset)); CHECK_EQ(fp.Read(&sz, sizeof(sz)), sizeof(sz));
CHECK_GT(json_offset, 0); CHECK_GT(sz, 0);
size_t json_offset = static_cast<size_t>(sz);
std::string buffer; std::string buffer;
common::FixedSizeStream{&fp}.Take(&buffer); common::FixedSizeStream{&fp}.Take(&buffer);