diff --git a/cpp/src/arrow/compute/kernels/scalar_cast_internal.cc b/cpp/src/arrow/compute/kernels/scalar_cast_internal.cc index 8cf5a04addb00..5f719d3621c12 100644 --- a/cpp/src/arrow/compute/kernels/scalar_cast_internal.cc +++ b/cpp/src/arrow/compute/kernels/scalar_cast_internal.cc @@ -52,7 +52,8 @@ struct CastPrimitive: // memcpy output static void Exec(const ArraySpan& arr, ArraySpan* out) { using T = typename InType::c_type; - std::memcpy(out->GetValues(1), arr.GetValues(1), arr.length * sizeof(T)); + std::memcpy(out->GetValues(1), arr.GetValues(1), + static_cast(arr.length) * sizeof(T)); } }; diff --git a/cpp/src/arrow/compute/kernels/scalar_cast_string.cc b/cpp/src/arrow/compute/kernels/scalar_cast_string.cc index ebeb597207a81..be97f36d0f3b1 100644 --- a/cpp/src/arrow/compute/kernels/scalar_cast_string.cc +++ b/cpp/src/arrow/compute/kernels/scalar_cast_string.cc @@ -247,7 +247,7 @@ Status CastBinaryToBinaryOffsets(KernelContext* ctx, output->buffers[1], ctx->Allocate((output->length + output->offset + 1) * sizeof(output_offset_type))); memset(output->buffers[1]->mutable_data(), 0, - output->offset * sizeof(output_offset_type)); + static_cast(output->offset) * sizeof(output_offset_type)); ::arrow::internal::CastInts(input.GetValues(1), output->GetMutableValues(1), output->length + 1); @@ -275,7 +275,7 @@ Status CastBinaryToBinaryOffsets(KernelContext* ctx, ctx->Allocate((output->length + output->offset + 1) * sizeof(output_offset_type))); memset(output->buffers[1]->mutable_data(), 0, - output->offset * sizeof(output_offset_type)); + static_cast(output->offset) * sizeof(output_offset_type)); ::arrow::internal::CastInts(input_offsets, output->GetMutableValues(1), output->length + 1); diff --git a/cpp/src/arrow/compute/kernels/scalar_compare.cc b/cpp/src/arrow/compute/kernels/scalar_compare.cc index aad648ca275c3..4b361cdeea643 100644 --- a/cpp/src/arrow/compute/kernels/scalar_compare.cc +++ b/cpp/src/arrow/compute/kernels/scalar_compare.cc @@ -660,7 +660,7 @@ struct BinaryScalarMinMax { bit_util::GetBit(array.buffers[0].data, array.offset + row)) { const auto offsets = array.GetValues(1); const auto data = array.GetValues(2, /*absolute_offset=*/0); - const int64_t length = offsets[row + 1] - offsets[row]; + const auto length = static_cast(offsets[row + 1] - offsets[row]); visit_value( string_view(reinterpret_cast(data + offsets[row]), length)); } else if (!options.skip_nulls) { diff --git a/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc b/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc index e2d5583e36e6b..a0b0b49d142ff 100644 --- a/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc +++ b/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc @@ -47,14 +47,14 @@ struct SetLookupState : public SetLookupStateBase { this->null_matching_behavior = options.GetNullMatchingBehavior(); if (options.value_set.is_array()) { const ArrayData& value_set = *options.value_set.array(); - memo_index_to_value_index.reserve(value_set.length); + memo_index_to_value_index.reserve(static_cast(value_set.length)); lookup_table = MemoTable(memory_pool, ::arrow::internal::HashTable::kLoadFactor * value_set.length); RETURN_NOT_OK(AddArrayValueSet(options, *options.value_set.array())); } else if (options.value_set.kind() == Datum::CHUNKED_ARRAY) { const ChunkedArray& value_set = *options.value_set.chunked_array(); - memo_index_to_value_index.reserve(value_set.length()); + memo_index_to_value_index.reserve(static_cast(value_set.length())); lookup_table = MemoTable(memory_pool, ::arrow::internal::HashTable::kLoadFactor * value_set.length()); @@ -290,7 +290,8 @@ struct IndexInVisitor { // Set all values to 0, which will be unmasked only if null is in the value_set // and null_matching_behavior is equal to MATCH - std::memset(out->GetValues(1), 0x00, out->length * sizeof(int32_t)); + std::memset(out->GetValues(1), 0x00, + static_cast(out->length) * sizeof(int32_t)); } return Status::OK(); } diff --git a/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc b/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc index a90a7282bb390..521178bcd7321 100644 --- a/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc +++ b/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc @@ -461,7 +461,7 @@ Status StringDataTransform(KernelContext* ctx, const ExecSpan& batch, } else { RETURN_NOT_OK(ctx->Allocate(offset_nbytes).Value(&out_arr->buffers[1])); std::memcpy(out_arr->buffers[1]->mutable_data(), input.buffers[1].data, - offset_nbytes); + static_cast(offset_nbytes)); } } else { // We must allocate new space for the offsets and shift the existing offsets @@ -1238,8 +1238,9 @@ struct PlainSubstringMatcher { for (size_t pos = 0; pos < pattern_length; ++pos) { // The prefix cannot be expanded, reset. while (prefix_length >= 0 && - options_.pattern[pos] != options_.pattern[prefix_length]) { - prefix_length = prefix_table[prefix_length]; + options_.pattern[pos] != + options_.pattern[static_cast(prefix_length)]) { + prefix_length = prefix_table[static_cast(prefix_length)]; } prefix_length++; prefix_table[pos + 1] = prefix_length; @@ -1253,8 +1254,9 @@ struct PlainSubstringMatcher { int64_t pos = 0; if (pattern_length == 0) return 0; for (const auto c : current) { - while ((pattern_pos >= 0) && (options_.pattern[pattern_pos] != c)) { - pattern_pos = prefix_table[pattern_pos]; + while ((pattern_pos >= 0) && + (options_.pattern[static_cast(pattern_pos)] != c)) { + pattern_pos = prefix_table[static_cast(pattern_pos)]; } pattern_pos++; if (static_cast(pattern_pos) == pattern_length) { @@ -1344,7 +1346,8 @@ struct MatchSubstringImpl { for (int64_t i = 0; i < length; ++i) { const char* current_data = reinterpret_cast(data + offsets[i]); int64_t current_length = offsets[i + 1] - offsets[i]; - if (matcher->Match(std::string_view(current_data, current_length))) { + if (matcher->Match(std::string_view(current_data, + static_cast(current_length)))) { bitmap_writer.Set(); } bitmap_writer.Next(); @@ -1805,7 +1808,7 @@ struct CountSubstring { uint64_t start = 0; const auto pattern_size = std::max(1, matcher_.options_.pattern.size()); while (start <= val.size()) { - const int64_t index = matcher_.Find(val.substr(start)); + const int64_t index = matcher_.Find(val.substr(static_cast(start))); if (index >= 0) { count++; start += index + pattern_size; @@ -3076,7 +3079,7 @@ struct BinaryJoinElementWise { bit_util::GetBit(array.buffers[0].data, array.offset + row)) { const offset_type* offsets = array.GetValues(1); const uint8_t* data = array.GetValues(2, /*absolute_offset=*/0); - const int64_t length = offsets[row + 1] - offsets[row]; + const auto length = static_cast(offsets[row + 1] - offsets[row]); valid_cols[col] = std::string_view( reinterpret_cast(data + offsets[row]), length); if (col < batch.num_values() - 1) num_valid++; @@ -3305,7 +3308,7 @@ struct BinaryRepeatTransform : public StringBinaryTransformBase { const int64_t num_repeats, uint8_t* output) { uint8_t* output_start = output; for (int64_t i = 0; i < num_repeats; ++i) { - std::memcpy(output, input, input_string_ncodeunits); + std::memcpy(output, input, static_cast(input_string_ncodeunits)); output += input_string_ncodeunits; } return output - output_start; @@ -3318,18 +3321,18 @@ struct BinaryRepeatTransform : public StringBinaryTransformBase { uint8_t* output_start = output; // Repeated doubling of string // NB: This implementation expects `num_repeats > 0`. - std::memcpy(output, input, input_string_ncodeunits); + std::memcpy(output, input, static_cast(input_string_ncodeunits)); output += input_string_ncodeunits; int64_t irep = 1; for (int64_t ilen = input_string_ncodeunits; irep <= (num_repeats / 2); irep *= 2, ilen *= 2) { - std::memcpy(output, output_start, ilen); + std::memcpy(output, output_start, static_cast(ilen)); output += ilen; } // Epilogue remainder int64_t rem = (num_repeats - irep) * input_string_ncodeunits; - std::memcpy(output, output_start, rem); + std::memcpy(output, output_start, static_cast(rem)); output += rem; return output - output_start; } diff --git a/cpp/src/arrow/compute/kernels/scalar_string_internal.h b/cpp/src/arrow/compute/kernels/scalar_string_internal.h index 1a9969441655d..e05cfa7fba371 100644 --- a/cpp/src/arrow/compute/kernels/scalar_string_internal.h +++ b/cpp/src/arrow/compute/kernels/scalar_string_internal.h @@ -364,7 +364,7 @@ struct StringSplitExec { // we will record the parts in reverse order parts.clear(); if (max_splits > -1) { - parts.reserve(max_splits + 1); + parts.reserve(static_cast(max_splits + 1)); } while (max_splits != 0) { const uint8_t *separator_begin, *separator_end; diff --git a/cpp/src/arrow/compute/kernels/scalar_string_utf8.cc b/cpp/src/arrow/compute/kernels/scalar_string_utf8.cc index cf8a697fea411..75ef500418566 100644 --- a/cpp/src/arrow/compute/kernels/scalar_string_utf8.cc +++ b/cpp/src/arrow/compute/kernels/scalar_string_utf8.cc @@ -558,12 +558,12 @@ struct Utf8NormalizeBase { ARROW_ASSIGN_OR_RAISE(const auto n_codepoints, DecomposeIntoScratch(v)); // Encode normalized codepoints directly into the output int64_t n_bytes = 0; - for (int64_t i = 0; i < n_codepoints; ++i) { + for (size_t i = 0; i < static_cast(n_codepoints); ++i) { n_bytes += ::arrow::util::UTF8EncodedLength(codepoints_[i]); } RETURN_NOT_OK(data_builder->Reserve(n_bytes)); uint8_t* out = data_builder->mutable_data() + data_builder->length(); - for (int64_t i = 0; i < n_codepoints; ++i) { + for (size_t i = 0; i < static_cast(n_codepoints); ++i) { out = ::arrow::util::UTF8Encode(out, codepoints_[i]); } DCHECK_EQ(out - data_builder->mutable_data(), data_builder->length() + n_bytes);