This is an automated email from the ASF dual-hosted git repository.
felixybw pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git
The following commit(s) were added to refs/heads/main by this push:
new abccde3cea [GLUTEN-8475][VL] Fix C-style casts to C++-style (#8474)
abccde3cea is described below
commit abccde3cea9ed8e7ab4aed9fb72440487cf5ee8f
Author: jkhaliqi <[email protected]>
AuthorDate: Fri Jan 17 14:19:06 2025 -0800
[GLUTEN-8475][VL] Fix C-style casts to C++-style (#8474)
Coupld of security volation fix
---
cpp/core/benchmarks/CompressionBenchmark.cc | 4 ++--
cpp/core/memory/MemoryAllocator.cc | 2 +-
cpp/core/shuffle/Spill.cc | 2 +-
cpp/core/utils/qat/QatCodec.cc | 4 ++--
cpp/core/utils/qpl/QplCodec.cc | 2 +-
cpp/velox/jni/JniFileSystem.cc | 5 +++--
.../operators/serializer/VeloxColumnarToRowConverter.cc | 2 +-
.../operators/serializer/VeloxRowToColumnarConverter.cc | 16 ++++++++--------
cpp/velox/shuffle/VeloxShuffleReader.cc | 2 +-
cpp/velox/shuffle/VeloxSortShuffleWriter.cc | 13 +++++++------
cpp/velox/substrait/SubstraitParser.cc | 2 +-
cpp/velox/tests/FunctionTest.cc | 10 ++++++----
cpp/velox/tests/VeloxSubstraitRoundTripTest.cc | 4 ++--
13 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/cpp/core/benchmarks/CompressionBenchmark.cc
b/cpp/core/benchmarks/CompressionBenchmark.cc
index aeeddf24e5..75ddf98aee 100644
--- a/cpp/core/benchmarks/CompressionBenchmark.cc
+++ b/cpp/core/benchmarks/CompressionBenchmark.cc
@@ -114,7 +114,7 @@ class BenchmarkCompression {
setCpu(state.range(2) + state.thread_index());
auto ipcWriteOptions = arrow::ipc::IpcWriteOptions::Defaults();
ipcWriteOptions.use_threads = false;
- auto compressBufferSize = (uint32_t)state.range(1);
+ auto compressBufferSize = static_cast<uint32_t>(state.range(1));
auto compressionType = state.range(0);
switch (compressionType) {
case gluten::kLZ4: {
@@ -253,7 +253,7 @@ class BenchmarkCompression {
GLUTEN_ASSIGN_OR_THROW(
auto len,
codec->Decompress(buffers[j]->size() - 8, buffers[j]->data() +
8, outputSize, out->mutable_data()));
- (void)len;
+ static_cast<void>(len);
}
}
}
diff --git a/cpp/core/memory/MemoryAllocator.cc
b/cpp/core/memory/MemoryAllocator.cc
index 84708962d0..c6180f53b3 100644
--- a/cpp/core/memory/MemoryAllocator.cc
+++ b/cpp/core/memory/MemoryAllocator.cc
@@ -162,7 +162,7 @@ bool StdMemoryAllocator::reallocateAligned(void* p,
uint64_t alignment, int64_t
return false;
}
if (newSize <= size) {
- auto aligned = ROUND_TO_LINE(newSize, alignment);
+ auto aligned = ROUND_TO_LINE(static_cast<uint64_t>(newSize), alignment);
if (aligned <= size) {
// shrink-to-fit
return reallocate(p, size, aligned, out);
diff --git a/cpp/core/shuffle/Spill.cc b/cpp/core/shuffle/Spill.cc
index 8cc3a9d05e..9b60d4bc3e 100644
--- a/cpp/core/shuffle/Spill.cc
+++ b/cpp/core/shuffle/Spill.cc
@@ -25,7 +25,7 @@ Spill::Spill(Spill::SpillType type) : type_(type) {}
Spill::~Spill() {
if (is_) {
- (void)is_->Close();
+ static_cast<void>(is_->Close());
}
}
diff --git a/cpp/core/utils/qat/QatCodec.cc b/cpp/core/utils/qat/QatCodec.cc
index e01fa96988..c86fc3bc21 100644
--- a/cpp/core/utils/qat/QatCodec.cc
+++ b/cpp/core/utils/qat/QatCodec.cc
@@ -38,8 +38,8 @@ class QatZipCodec : public arrow::util::Codec {
explicit QatZipCodec(int compressionLevel) :
compressionLevel_(compressionLevel) {}
~QatZipCodec() {
- (void)qzTeardownSession(&qzSession_);
- (void)qzClose(&qzSession_);
+ static_cast<void>(qzTeardownSession(&qzSession_));
+ static_cast<void>(qzClose(&qzSession_));
}
arrow::Result<int64_t> Decompress(int64_t inputLen, const uint8_t* input,
int64_t outputLen, uint8_t* output)
diff --git a/cpp/core/utils/qpl/QplCodec.cc b/cpp/core/utils/qpl/QplCodec.cc
index 0bf2ec36e7..b41a00585e 100644
--- a/cpp/core/utils/qpl/QplCodec.cc
+++ b/cpp/core/utils/qpl/QplCodec.cc
@@ -203,7 +203,7 @@ class QplGzipCodec final : public arrow::util::Codec {
int64_t MaxCompressedLen(int64_t input_len, const uint8_t*
ARROW_ARG_UNUSED(input)) override {
ARROW_DCHECK_GE(input_len, 0);
/// Aligned with ZLIB
- return ((input_len) + ((input_len) >> 12) + ((input_len) >> 14) +
((input_len) >> 25) + 13);
+ return ((input_len) + ((input_len) >> 12) + ((input_len) >> 14) +
((input_len) >> 25) + 13LL);
}
arrow::Result<std::shared_ptr<arrow::util::Compressor>> MakeCompressor()
override {
diff --git a/cpp/velox/jni/JniFileSystem.cc b/cpp/velox/jni/JniFileSystem.cc
index 7c2b198bbc..40a499a878 100644
--- a/cpp/velox/jni/JniFileSystem.cc
+++ b/cpp/velox/jni/JniFileSystem.cc
@@ -338,11 +338,12 @@ class JniFileSystem : public
facebook::velox::filesystems::FileSystem {
JNIEnv* env = nullptr;
attachCurrentThreadAsDaemonOrThrow(vm, &env);
std::vector<std::string> out;
- jobjectArray jarray = (jobjectArray)env->CallObjectMethod(obj_,
jniFileSystemList, createJString(env, path));
+ jobjectArray jarray =
+ static_cast<jobjectArray>(env->CallObjectMethod(obj_,
jniFileSystemList, createJString(env, path)));
checkException(env);
jsize length = env->GetArrayLength(jarray);
for (jsize i = 0; i < length; ++i) {
- jstring element = (jstring)env->GetObjectArrayElement(jarray, i);
+ jstring element =
static_cast<jstring>(env->GetObjectArrayElement(jarray, i));
std::string cElement = jStringToCString(env, element);
out.push_back(cElement);
}
diff --git a/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc
b/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc
index f9c910a624..91ff219a7e 100644
--- a/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc
+++ b/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc
@@ -80,7 +80,7 @@ void
VeloxColumnarToRowConverter::convert(std::shared_ptr<ColumnarBatch> cb, int
size_t offset = 0;
for (auto i = 0; i < numRows_; ++i) {
- auto rowSize = fast_->serialize(startRow + i, (char*)(bufferAddress_ +
offset));
+ auto rowSize = fast_->serialize(startRow + i,
reinterpret_cast<char*>(bufferAddress_ + offset));
lengths_[i] = rowSize;
if (i > 0) {
offsets_[i] = offsets_[i - 1] + lengths_[i - 1];
diff --git a/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc
b/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc
index 1ec043e660..28a7279a2b 100644
--- a/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc
+++ b/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc
@@ -35,7 +35,7 @@ inline int64_t getFieldOffset(int64_t nullBitsetWidthInBytes,
int32_t index) {
inline bool isNull(uint8_t* buffer_address, int32_t index) {
int64_t mask = 1L << (static_cast<int64_t>(index) & 0x3f); // mod 64 and
shift
int64_t wordOffset = (static_cast<int64_t>(index) >> 6) * 8;
- int64_t value = *((int64_t*)(buffer_address + wordOffset));
+ int64_t value = *reinterpret_cast<int64_t*>(buffer_address + wordOffset);
return (value & mask) != 0;
}
@@ -51,7 +51,7 @@ int32_t getTotalStringSize(
continue;
}
- int64_t offsetAndSize = *(int64_t*)(memoryAddress + offsets[pos] +
fieldOffset);
+ int64_t offsetAndSize = *(reinterpret_cast<int64_t*>(memoryAddress +
offsets[pos] + fieldOffset));
int32_t length = static_cast<int32_t>(offsetAndSize);
if (!StringView::isInline(length)) {
size += length;
@@ -98,11 +98,11 @@ VectorPtr createFlatVector<TypeKind::HUGEINT>(
auto column = BaseVector::create<FlatVector<int128_t>>(type, numRows, pool);
auto rawValues = column->mutableRawValues<uint8_t>();
auto typeWidth = sizeof(int128_t);
- auto shift = __builtin_ctz((uint32_t)typeWidth);
+ auto shift = __builtin_ctz(static_cast<uint32_t>(typeWidth));
for (auto pos = 0; pos < numRows; pos++) {
if (!isNull(memoryAddress + offsets[pos], columnIdx)) {
uint8_t* destptr = rawValues + (pos << shift);
- int64_t offsetAndSize = *(int64_t*)(memoryAddress + offsets[pos] +
fieldOffset);
+ int64_t offsetAndSize = *reinterpret_cast<int64_t*>(memoryAddress +
offsets[pos] + fieldOffset);
int32_t length = static_cast<int32_t>(offsetAndSize);
int32_t wordoffset = static_cast<int32_t>(offsetAndSize >> 32);
uint8_t bytesValue[length];
@@ -111,7 +111,7 @@ VectorPtr createFlatVector<TypeKind::HUGEINT>(
for (int k = length - 1; k >= 0; k--) {
bytesValue2[length - 1 - k] = bytesValue[k];
}
- if (int8_t(bytesValue[0]) < 0) {
+ if (static_cast<int8_t>(bytesValue[0]) < 0) {
memset(bytesValue2 + length, 255, 16 - length);
}
memcpy(destptr, bytesValue2, typeWidth);
@@ -135,7 +135,7 @@ VectorPtr createFlatVector<TypeKind::BOOLEAN>(
auto rawValues = column->mutableRawValues<uint64_t>();
for (auto pos = 0; pos < numRows; pos++) {
if (!isNull(memoryAddress + offsets[pos], columnIdx)) {
- bool value = *(bool*)(memoryAddress + offsets[pos] + fieldOffset);
+ bool value = *(reinterpret_cast<bool*>(memoryAddress + offsets[pos] +
fieldOffset));
bits::setBit(rawValues, pos, value);
} else {
column->setNull(pos, true);
@@ -156,7 +156,7 @@ VectorPtr createFlatVector<TypeKind::TIMESTAMP>(
auto column = BaseVector::create<FlatVector<Timestamp>>(type, numRows, pool);
for (auto pos = 0; pos < numRows; pos++) {
if (!isNull(memoryAddress + offsets[pos], columnIdx)) {
- int64_t value = *(int64_t*)(memoryAddress + offsets[pos] + fieldOffset);
+ int64_t value = *reinterpret_cast<int64_t*>(memoryAddress + offsets[pos]
+ fieldOffset);
column->set(pos, Timestamp::fromMicros(value));
} else {
column->setNull(pos, true);
@@ -178,7 +178,7 @@ VectorPtr createFlatVectorStringView(
char* rawBuffer = column->getRawStringBufferWithSpace(size, true);
for (auto pos = 0; pos < numRows; pos++) {
if (!isNull(memoryAddress + offsets[pos], columnIdx)) {
- int64_t offsetAndSize = *(int64_t*)(memoryAddress + offsets[pos] +
fieldOffset);
+ int64_t offsetAndSize = *(reinterpret_cast<int64_t*>(memoryAddress +
offsets[pos] + fieldOffset));
int32_t length = static_cast<int32_t>(offsetAndSize);
int32_t wordoffset = static_cast<int32_t>(offsetAndSize >> 32);
auto valueSrcPtr = memoryAddress + offsets[pos] + wordoffset;
diff --git a/cpp/velox/shuffle/VeloxShuffleReader.cc
b/cpp/velox/shuffle/VeloxShuffleReader.cc
index 3aba7cf0fc..bc3d9bcb03 100644
--- a/cpp/velox/shuffle/VeloxShuffleReader.cc
+++ b/cpp/velox/shuffle/VeloxShuffleReader.cc
@@ -440,7 +440,7 @@ std::shared_ptr<ColumnarBatch>
VeloxSortShuffleReaderDeserializer::deserializeTo
auto buffer = cur->second;
const auto* rawBuffer = buffer->as<char>();
while (rowOffset_ < cur->first && readRows < batchSize_) {
- auto rowSize = *(RowSizeType*)(rawBuffer + byteOffset_) -
sizeof(RowSizeType);
+ auto rowSize = *(reinterpret_cast<const RowSizeType*>(rawBuffer +
byteOffset_)) - sizeof(RowSizeType);
byteOffset_ += sizeof(RowSizeType);
data.push_back(std::string_view(rawBuffer + byteOffset_, rowSize));
byteOffset_ += rowSize;
diff --git a/cpp/velox/shuffle/VeloxSortShuffleWriter.cc
b/cpp/velox/shuffle/VeloxSortShuffleWriter.cc
index 80d0349bc9..52a5240186 100644
--- a/cpp/velox/shuffle/VeloxSortShuffleWriter.cc
+++ b/cpp/velox/shuffle/VeloxSortShuffleWriter.cc
@@ -34,11 +34,11 @@ constexpr uint32_t kPartitionIdEndByteIndex = 7;
uint64_t toCompactRowId(uint32_t partitionId, uint32_t pageNumber, uint32_t
offsetInPage) {
// |63 partitionId(24) |39 inputIndex(13) |26 rowIndex(27) |
- return (uint64_t)partitionId << 40 | (uint64_t)pageNumber << 27 |
offsetInPage;
+ return static_cast<uint64_t>(partitionId) << 40 |
static_cast<uint64_t>(pageNumber) << 27 | offsetInPage;
}
uint32_t extractPartitionId(uint64_t compactRowId) {
- return (uint32_t)(compactRowId >> 40);
+ return static_cast<uint32_t>(compactRowId >> 40);
}
std::pair<uint32_t, uint32_t> extractPageNumberAndOffset(uint64_t
compactRowId) {
@@ -187,7 +187,7 @@ arrow::Status VeloxSortShuffleWriter::insert(const
facebook::velox::RowVectorPtr
auto rows = maxRowsToInsert(rowOffset, remainingRows);
if (rows == 0) {
auto minSizeRequired = fixedRowSize_ ? fixedRowSize_.value() :
rowSize_[rowOffset];
- acquireNewBuffer((uint64_t)memLimit, minSizeRequired);
+ acquireNewBuffer(static_cast<uint64_t>(memLimit), minSizeRequired);
rows = maxRowsToInsert(rowOffset, remainingRows);
ARROW_RETURN_IF(
rows == 0, arrow::Status::Invalid("Failed to insert rows. Remaining
rows: " + std::to_string(remainingRows)));
@@ -294,7 +294,7 @@ arrow::Status
VeloxSortShuffleWriter::evictPartition(uint32_t partitionId, size_
while (index < end) {
auto pageIndex = extractPageNumberAndOffset(arrayPtr_[index]);
addr = pageAddresses_[pageIndex.first] + pageIndex.second;
- size = *(RowSizeType*)addr;
+ size = *(reinterpret_cast<RowSizeType*>(addr));
if (offset + size > options_.sortEvictBufferSize && offset > 0) {
sortTime.stop();
RETURN_NOT_OK(evictPartitionInternal(partitionId, index - begin,
rawBuffer_, offset));
@@ -302,7 +302,7 @@ arrow::Status
VeloxSortShuffleWriter::evictPartition(uint32_t partitionId, size_
begin = index;
offset = 0;
}
- if (size > options_.sortEvictBufferSize) {
+ if (size > static_cast<uint32_t>(options_.sortEvictBufferSize)) {
// Split large rows.
sortTime.stop();
RowSizeType bytes = 0;
@@ -355,7 +355,8 @@ facebook::velox::vector_size_t
VeloxSortShuffleWriter::maxRowsToInsert(
}
auto remainingBytes = pages_.back()->size() - pageCursor_;
if (fixedRowSize_) {
- return std::min((facebook::velox::vector_size_t)(remainingBytes /
(fixedRowSize_.value())), remainingRows);
+ return std::min(
+ static_cast<facebook::velox::vector_size_t>(remainingBytes /
(fixedRowSize_.value())), remainingRows);
}
auto beginIter = rowSizePrefixSum_.begin() + 1 + offset;
auto bytesWritten = rowSizePrefixSum_[offset];
diff --git a/cpp/velox/substrait/SubstraitParser.cc
b/cpp/velox/substrait/SubstraitParser.cc
index bdbcc2785d..1b689baa1b 100644
--- a/cpp/velox/substrait/SubstraitParser.cc
+++ b/cpp/velox/substrait/SubstraitParser.cc
@@ -327,7 +327,7 @@ int16_t SubstraitParser::getLiteralValue(const
::substrait::Expression::Literal&
template <>
int32_t SubstraitParser::getLiteralValue(const
::substrait::Expression::Literal& literal) {
if (literal.has_date()) {
- return int32_t(literal.date());
+ return static_cast<int32_t>(literal.date());
}
return literal.i32();
}
diff --git a/cpp/velox/tests/FunctionTest.cc b/cpp/velox/tests/FunctionTest.cc
index c149b2db38..01046961fb 100644
--- a/cpp/velox/tests/FunctionTest.cc
+++ b/cpp/velox/tests/FunctionTest.cc
@@ -153,11 +153,13 @@ TEST_F(FunctionTest, setVectorFromVariants) {
// Floats are harder to compare because of low-precision. Just making sure
// they don't throw.
- EXPECT_NO_THROW(setVectorFromVariants(REAL(), {variant(float(0.99L)),
variant(float(-1.99L))}, pool_.get()));
+ EXPECT_NO_THROW(setVectorFromVariants(
+ REAL(), {variant(static_cast<float>(0.99L)),
variant(static_cast<float>(-1.99L))}, pool_.get()));
- resultVec = setVectorFromVariants(DOUBLE(), {variant(double(0.99L)),
variant(double(-1.99L))}, pool_.get());
- ASSERT_EQ(double(0.99L), resultVec->asFlatVector<double>()->valueAt(0));
- ASSERT_EQ(double(-1.99L), resultVec->asFlatVector<double>()->valueAt(1));
+ resultVec = setVectorFromVariants(
+ DOUBLE(), {variant(static_cast<double>(0.99L)),
variant(static_cast<double>(-1.99L))}, pool_.get());
+ ASSERT_EQ(static_cast<double>(0.99L),
resultVec->asFlatVector<double>()->valueAt(0));
+ ASSERT_EQ(static_cast<double>(-1.99L),
resultVec->asFlatVector<double>()->valueAt(1));
resultVec = setVectorFromVariants(VARCHAR(), {variant(""), variant("asdf")},
pool_.get());
ASSERT_EQ("", resultVec->asFlatVector<StringView>()->valueAt(0).str());
diff --git a/cpp/velox/tests/VeloxSubstraitRoundTripTest.cc
b/cpp/velox/tests/VeloxSubstraitRoundTripTest.cc
index de338a3c43..ed210d48bc 100644
--- a/cpp/velox/tests/VeloxSubstraitRoundTripTest.cc
+++ b/cpp/velox/tests/VeloxSubstraitRoundTripTest.cc
@@ -371,10 +371,10 @@ TEST_F(VeloxSubstraitRoundTripTest, notNullLiteral) {
makeConstantExpr(BOOLEAN(), static_cast<bool>(1)),
makeConstantExpr(TINYINT(), static_cast<int8_t>(23)),
makeConstantExpr(SMALLINT(), static_cast<int16_t>(45)),
- makeConstantExpr(INTEGER(), static_cast<int32_t>(678)),
+ makeConstantExpr(INTEGER(), 678),
makeConstantExpr(BIGINT(), static_cast<int64_t>(910)),
makeConstantExpr(REAL(), static_cast<float>(1.23)),
- makeConstantExpr(DOUBLE(), static_cast<double>(4.56)),
+ makeConstantExpr(DOUBLE(), 4.56),
makeConstantExpr(VARCHAR(), "789")};
return std::make_shared<core::ProjectNode>(
id, std::move(projectNames),
std::move(projectExpressions), input);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]