MCPcopy Create free account
hub / github.com/apache/arrow / safe_add_separators

Function safe_add_separators

cpp/src/gandiva/precompiled/string_ops.cc:2651–2674  ·  view source on GitHub ↗

Helper to safely add separators based on number of valid words

Source from the content-addressed store, hash-verified

2649
2650// Helper to safely add separators based on number of valid words
2651static inline bool safe_add_separators(int64_t context, SafeLengthState* state,
2652 int32_t separator_len) {
2653 if (state->num_valid <= 1) return true;
2654
2655 int32_t sep_total = 0;
2656 int32_t temp = 0;
2657
2658 if (ARROW_PREDICT_FALSE(arrow::internal::MultiplyWithOverflow(
2659 separator_len, state->num_valid - 1, &sep_total))) {
2660 gdv_fn_context_set_error_msg(context, "Overflow in multiplication detected.");
2661 state->overflow = true;
2662 return false;
2663 }
2664
2665 if (ARROW_PREDICT_FALSE(
2666 arrow::internal::AddWithOverflow(state->total_len, sep_total, &temp))) {
2667 gdv_fn_context_set_error_msg(context, "Overflow in addition detected.");
2668 state->overflow = true;
2669 return false;
2670 }
2671
2672 state->total_len = temp;
2673 return true;
2674}
2675
2676// Helper to handle overflow failure (sets output parameters and returns empty string)
2677static inline const char* handle_overflow_failure(bool* out_valid, int32_t* out_len) {

Callers 1

concat_ws_implFunction · 0.85

Calls 3

MultiplyWithOverflowFunction · 0.85
AddWithOverflowFunction · 0.85

Tested by

no test coverage detected