lriggs commented on code in PR #49471:
URL: https://github.com/apache/arrow/pull/49471#discussion_r2908367754


##########
cpp/src/gandiva/gdv_string_function_stubs.cc:
##########
@@ -407,14 +407,17 @@ const char* gdv_fn_substring_index(int64_t context, const 
char* txt, int32_t txt
     }
   }
 
-  if (static_cast<int32_t>(abs(cnt)) <= static_cast<int32_t>(occ.size()) && 
cnt > 0) {
+  // Use int64_t to avoid undefined behavior with abs(INT_MIN)
+  int64_t abs_cnt = (cnt < 0) ? -static_cast<int64_t>(cnt) : 
static_cast<int64_t>(cnt);

Review Comment:
   Is it possible to check the function parameter for the bad size and exit 
early like in the truncation fix? That seems simpler.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to