Skip to content

Commit 6422164

Browse files
committed
[demangler] Make OutputBuffer non-copyable
In addressing the buffer ownership API, I discovered a rogue member function that returned by value rather than by reference. It clearly intended to return by reference, but because the copy ctor wasn't deleted this wasn't caught. It is not necessary to make this a move-only type, although that would be an alternative. Reviewed By: bruno Differential Revision: https://reviews.llvm.org/D120901
1 parent 6afe035 commit 6422164

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

libcxxabi/src/demangle/Utility.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class OutputBuffer {
7171
OutputBuffer(char *StartBuf, size_t Size)
7272
: Buffer(StartBuf), CurrentPosition(0), BufferCapacity(Size) {}
7373
OutputBuffer() = default;
74+
// Non-copyable
75+
OutputBuffer(const OutputBuffer &) = delete;
76+
OutputBuffer &operator=(const OutputBuffer &) = delete;
77+
7478
void reset(char *Buffer_, size_t BufferCapacity_) {
7579
CurrentPosition = 0;
7680
Buffer = Buffer_;
@@ -97,7 +101,7 @@ class OutputBuffer {
97101
return *this;
98102
}
99103

100-
OutputBuffer prepend(StringView R) {
104+
OutputBuffer &prepend(StringView R) {
101105
size_t Size = R.size();
102106

103107
grow(Size);

llvm/include/llvm/Demangle/Utility.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class OutputBuffer {
7171
OutputBuffer(char *StartBuf, size_t Size)
7272
: Buffer(StartBuf), CurrentPosition(0), BufferCapacity(Size) {}
7373
OutputBuffer() = default;
74+
// Non-copyable
75+
OutputBuffer(const OutputBuffer &) = delete;
76+
OutputBuffer &operator=(const OutputBuffer &) = delete;
77+
7478
void reset(char *Buffer_, size_t BufferCapacity_) {
7579
CurrentPosition = 0;
7680
Buffer = Buffer_;
@@ -97,7 +101,7 @@ class OutputBuffer {
97101
return *this;
98102
}
99103

100-
OutputBuffer prepend(StringView R) {
104+
OutputBuffer &prepend(StringView R) {
101105
size_t Size = R.size();
102106

103107
grow(Size);

0 commit comments

Comments
 (0)