[PATCH] D144706: [Support][MemBuffer] Prevent UB on empty StringRefs

Kadir Cetinkaya via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 24 02:34:47 PST 2023


kadircet added inline comments.


================
Comment at: llvm/lib/Support/MemoryBuffer.cpp:138
     return make_error_code(errc::not_enough_memory);
-  memcpy(Buf->getBufferStart(), InputData.data(), InputData.size());
+  // Calling memcpy with null src/dst is UB, and an empty StringRef is
+  // represented with {nullptr, 0}. Make sure we don't copy anything in that
----------------
sammccall wrote:
> instead of the check + comment, you can use std::copy which doesn't have this deficiency
thanks that makes sense, i'd be happy to change it to use `std::copy` if there are no objections anytime soon


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144706



More information about the llvm-commits mailing list