[llvm] [MC] AsmLexer assert buffer is null-terminated at CurBuf.end() (PR #154972)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 18 18:36:25 PDT 2025
================
@@ -120,6 +120,11 @@ AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) {
void AsmLexer::setBuffer(StringRef Buf, const char *ptr,
bool EndStatementAtEOF) {
+ // Null terminator must be part of the actual buffer. It must reside at
+ // `Buf.end()`. It must be safe to dereference `Buf.end()`.
+ assert(*Buf.end() == '\0' &&
----------------
MaskRay wrote:
I think it's right to require a NUL terminator, like regular `MemoryBuffer` APIs provide (`getFileOrSTDIN` `MemoryBuffer::getFile`.
We should add a comment to the header file `llvm/include/llvm/MC/MCParser/AsmLexer.h` about this requirement.
https://github.com/llvm/llvm-project/pull/154972
More information about the llvm-commits
mailing list