Helper to safely add separators based on number of valid words
| 2649 | |
| 2650 | // Helper to safely add separators based on number of valid words |
| 2651 | static 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) |
| 2677 | static inline const char* handle_overflow_failure(bool* out_valid, int32_t* out_len) { |
no test coverage detected