[PATCH] D144706: [Support][MemBuffer] Prevent UB on empty StringRefs
Sam McCall via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 24 02:16:36 PST 2023
sammccall 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
----------------
instead of the check + comment, you can use std::copy which doesn't have this deficiency
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