vvellanki commented on a change in pull request #11287: URL: https://github.com/apache/arrow/pull/11287#discussion_r747696180
########## File path: cpp/src/gandiva/precompiled/string_ops.cc ########## @@ -2195,4 +2195,22 @@ const char* byte_substr_binary_int32_int32(gdv_int64 context, const char* text, memcpy(ret, text + startPos, *out_len); return ret; } + +FORCE_INLINE +int32_t instr_utf8(const char* string, int32_t string_len, const char* substring, + int32_t substring_len) { + if (substring_len == 0) { + return 1; + } + + int32_t end_idx = + (string_len - substring_len) <= 0 ? string_len : string_len - substring_len; + + for (int i = 0; i < end_idx; i++) { Review comment: Let the input be: "Hello" with string_len = 5 substring = "lower" with substring_len = 5 end_idx = 5 in this case For i = 2, string[i] = 'l' = substring[0]. The memcmp() is going to access string + i + substring_len, which is string + 2 + 5 = string + 7. string + 7 is out of range of the input. We cannot do this, it will cause issues -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org