[Lldb-commits] [PATCH] D101390: Change Target::ReadMemory to ensure the amount of memory read from the file-cache is the amount requested.

Shafik Yaghmour via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 29 09:30:14 PDT 2021


shafik added inline comments.


================
Comment at: lldb/source/Target/Target.cpp:1778
+        else if (file_cache_bytes_read > 0) {
+          file_cache_read_buffer.reset(malloc(file_cache_bytes_read));
+          std::memcpy(file_cache_read_buffer.get(), dst, file_cache_bytes_read);
----------------
augusto2112 wrote:
> shafik wrote:
> > augusto2112 wrote:
> > > shafik wrote:
> > > > Is there a reason why we need to use `malloc` and `free`?
> > > Since the type is void I thought that was the correct way. What should I use instead?
> > I looked at the places we are calling `Target::ReadMemory` and they are using some form of a `uint8_t` buffer. So a `uint8_t` array would be fine:
> > 
> > ```
> > std::unique_ptr<uint8_t[]> file_cache_read_buffer;
> > //....
> > p = std::make_unique<uint8_t[]>(file_cache_bytes_read);
> > 
> > ```
> Thanks Shakif, it does look a bit simpler now.
`std::vector` for a buffer is also possible some callers do that but I don't see a reason to prefer that over this solution.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101390/new/

https://reviews.llvm.org/D101390



More information about the lldb-commits mailing list