edponce commented on a change in pull request #11023:
URL: https://github.com/apache/arrow/pull/11023#discussion_r739524798



##########
File path: cpp/src/arrow/compute/kernels/scalar_string.cc
##########
@@ -402,16 +401,16 @@ struct StringTransformExecBase {
     if (!input.is_valid) {
       return Status::OK();
     }
-    auto* result = checked_cast<BaseBinaryScalar*>(out->scalar().get());
-    result->is_valid = true;
     const int64_t data_nbytes = static_cast<int64_t>(input.value->size());
-
     const int64_t output_ncodeunits_max = transform->MaxCodeunits(1, 
data_nbytes);
     if (output_ncodeunits_max > std::numeric_limits<offset_type>::max()) {
       return Status::CapacityError(
           "Result might not fit in a 32bit utf8 array, convert to large_utf8");
     }
+
     ARROW_ASSIGN_OR_RAISE(auto value_buffer, 
ctx->Allocate(output_ncodeunits_max));
+    auto* result = checked_cast<BaseBinaryScalar*>(out->scalar().get());

Review comment:
       After a bit of more thought, it is not that easy to enforce because in 
many cases the pointer is dereferenced beforehand:
   ```c++
   const auto& obs = checked_cast<const Type&>(*some_var);
   ```
   So the more general question is when should pointers  be checked for 
nullity? Should we check everywhere a raw pointer is accessed?




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