Issue 171479
Summary MemoryBuffer has poor type safety
Labels new issue
Assignees
Reporter tamird
    Back in ea5a137e558f36602616268ede35dcfeb92aa3e3 `MemoryBuffer` was overloaded to be *sometimes* null-terminated. Since then a number of conversion functions were added that further muddy the waters and make it difficult to reason about whether the null terminator is present or not (e.g. conversion to and from `MemoryBufferRef` which is backed by `StringRef`, which is explicitly not null-terminated).

Removing null termination is not an option - various parsers rely on the null terminator as an optimization. This also means that constructing `MemoryBuffer` for use with parsers is fragile: if the buffer contains an interior null byte, parsing will end earlier than the caller expects.

Type safety can be improved by splitting this type into two: one null terminated, one not. The null terminated type should take the full length at construction (including the null terminator) and check that there aren't any interior null bytes.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to