anthonylouisbsb commented on a change in pull request #10195:
URL: https://github.com/apache/arrow/pull/10195#discussion_r623052850
##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -1520,4 +1521,42 @@ const char* binary_string(gdv_int64 context, const char*
text, gdv_int32 text_le
return ret;
}
+// Gets a binary object and returns its hexadecimal representation. That
representation
+// maps each byte in the input to a 2-length string containing a hexadecimal
number.
+// - Examples:
+// - foo -> 666F6F = 66[f] 6F[o] 6F[o]
+// - bar -> 626172 = 62[b] 61[a] 72[r]
+FORCE_INLINE
+const char* to_hex_binary(gdv_int64 context, const char* text, gdv_int32
text_len,
+ gdv_int32* out_len) {
+ if (text_len == 0) {
+ *out_len = 0;
+ return "";
+ }
+
+ auto ret =
+ reinterpret_cast<gdv_utf8>(gdv_fn_context_arena_malloc(context, text_len
* 2));
+
+ if (ret == nullptr) {
+ gdv_fn_context_set_error_msg(context, "Could not allocate memory for
output string");
+ *out_len = 0;
+ return "";
+ }
+
+ gdv_uint32 ret_index = 0;
+ gdv_uint32 max_len = static_cast<gdv_uint32>(text_len) * 2;
+ gdv_uint32 max_char_to_write = 4;
+
+ for (gdv_int32 i = 0; i < text_len; i++) {
+ DCHECK(ret_index >= 0 && ret_index < max_len);
Review comment:
It is a security pattern, as was recommended in that PR
https://github.com/apache/arrow/pull/9707#discussion_r597387398
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]