vvellanki commented on a change in pull request #11287:
URL: https://github.com/apache/arrow/pull/11287#discussion_r756057201



##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -2465,4 +2465,22 @@ const char* elt_int32_utf8_utf8_utf8_utf8_utf8(
       return nullptr;
   }
 }
+
+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 =

Review comment:
       else, your end_idx = string_len - substring_len;
   
   And, your for loop should go from i = 0; to i <= end_idx

##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -2465,4 +2465,22 @@ const char* elt_int32_utf8_utf8_utf8_utf8_utf8(
       return nullptr;
   }
 }
+
+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 =

Review comment:
       if (string_len < substring_len) - shouldn't this return 0 without any 
further checking?

##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -2465,4 +2465,22 @@ const char* elt_int32_utf8_utf8_utf8_utf8_utf8(
       return nullptr;
   }
 }
+
+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++) {
+    if (string[i] == substring[0] && strncmp(string + i, substring, 
substring_len) == 0) {

Review comment:
       You cannot use strncmp() since this terminates if it sees a '\0' char. 
You should use memcmp() with the appropriate size




-- 
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


Reply via email to