[ 
https://issues.apache.org/jira/browse/ARROW-2275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16392991#comment-16392991
 ] 

ASF GitHub Bot commented on ARROW-2275:
---------------------------------------

wesm commented on a change in pull request #1717: ARROW-2275: [C++] Guard 
against bad use of Buffer.mutable_data()
URL: https://github.com/apache/arrow/pull/1717#discussion_r173478791
 
 

 ##########
 File path: cpp/src/arrow/buffer.cc
 ##########
 @@ -70,6 +70,14 @@ Status Buffer::FromString(const std::string& data, 
std::shared_ptr<Buffer>* out)
   return FromString(data, default_memory_pool(), out);
 }
 
+#ifndef NDEBUG
+// DCHECK macros aren't allowed in public include files
+uint8_t* Buffer::mutable_data() {
+  DCHECK(is_mutable());
+  return mutable_data_;
+}
+#endif
 
 Review comment:
   This is a good idea, thank you

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [C++] Buffer::mutable_data_ member uninitialized
> ------------------------------------------------
>
>                 Key: ARROW-2275
>                 URL: https://issues.apache.org/jira/browse/ARROW-2275
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: C++
>    Affects Versions: 0.8.0
>            Reporter: Antoine Pitrou
>            Priority: Minor
>              Labels: pull-request-available
>
> For immutable buffers (i.e. most of them), the {{mutable_data_}} member is 
> uninitialized. If the user calls {{mutable_data()}} by mistake on such a 
> buffer, they will get a bogus pointer back.
> This is exacerbated by the Tensor API whose const and non-const 
> {{raw_data()}} methods return different things...
> (also an idea: add a DCHECK for mutability before returning from 
> {{mutable_data()}}?)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to