Skip to content

Commit 6257ffe

Browse files
committed
Fix realloc_buffer function
1 parent d936479 commit 6257ffe

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pch_mgr.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ const char* ResourceManager::realloc_buffer(const char *id,
107107
size_t alloc_size = requireNullTerminate ? size + 1 : size;
108108
buffer.resize(alloc_size);
109109
buffer.assign(buf, buf + size);
110-
buffer.back() = '\0';
110+
// The data in the buffer will be eventually passed to llvm::MemoryBufferMem
111+
// ctor via argument of StringRef type. The Length of this StringRef will be
112+
// = the 'size' argument of this function. There is an assert in
113+
// llvm::MemoryBuffer::init checking that element *past the end* of the memory
114+
// range passed via the ctor is '\0'. So we add it here.
115+
buffer.push_back('\0');
111116

112117
return &buffer[0];
113118
}

0 commit comments

Comments
 (0)