[compiler-rt] 70b2921 - [scudo] Remove ScopedString::Length
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 4 18:29:01 PDT 2021
Author: Vitaly Buka
Date: 2021-06-04T18:28:51-07:00
New Revision: 70b29213eb3446ffb85678da3cc447f478e27e15
URL: https://github.com/llvm/llvm-project/commit/70b29213eb3446ffb85678da3cc447f478e27e15
DIFF: https://github.com/llvm/llvm-project/commit/70b29213eb3446ffb85678da3cc447f478e27e15.diff
LOG: [scudo] Remove ScopedString::Length
Differential Revision: https://reviews.llvm.org/D103725
Added:
Modified:
compiler-rt/lib/scudo/standalone/string_utils.cpp
compiler-rt/lib/scudo/standalone/string_utils.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/string_utils.cpp b/compiler-rt/lib/scudo/standalone/string_utils.cpp
index ca80834cca87..acf85889fcff 100644
--- a/compiler-rt/lib/scudo/standalone/string_utils.cpp
+++ b/compiler-rt/lib/scudo/standalone/string_utils.cpp
@@ -219,7 +219,6 @@ int formatString(char *Buffer, uptr BufferLength, const char *Format, ...) {
}
void ScopedString::append(const char *Format, va_list Args) {
- RAW_CHECK(Length <= String.size());
va_list ArgsCopy;
va_copy(ArgsCopy, Args);
// formatString doesn't currently support a null buffer or zero buffer length,
@@ -228,11 +227,13 @@ void ScopedString::append(const char *Format, va_list Args) {
char C[1];
const uptr AdditionalLength =
static_cast<uptr>(formatString(C, sizeof(C), Format, Args)) + 1;
+ const uptr Length = length();
String.resize(Length + AdditionalLength);
- formatString(String.data() + Length, AdditionalLength, Format, ArgsCopy);
+ const uptr FormattedLength = static_cast<uptr>(formatString(
+ String.data() + Length, String.size() - Length, Format, ArgsCopy));
+ RAW_CHECK(data()[length()] == '\0');
+ RAW_CHECK(FormattedLength + 1 == AdditionalLength);
va_end(ArgsCopy);
- Length = strlen(String.data());
- RAW_CHECK(Length < String.size());
}
FORMAT(2, 3)
diff --git a/compiler-rt/lib/scudo/standalone/string_utils.h b/compiler-rt/lib/scudo/standalone/string_utils.h
index 7d9c539c2711..06d23d42246d 100644
--- a/compiler-rt/lib/scudo/standalone/string_utils.h
+++ b/compiler-rt/lib/scudo/standalone/string_utils.h
@@ -19,12 +19,11 @@ namespace scudo {
class ScopedString {
public:
explicit ScopedString() { String.push_back('\0'); }
- uptr length() { return Length; }
+ uptr length() { return String.size() - 1; }
const char *data() { return String.data(); }
void clear() {
String.clear();
String.push_back('\0');
- Length = 0;
}
void append(const char *Format, va_list Args);
void append(const char *Format, ...);
@@ -32,7 +31,6 @@ class ScopedString {
private:
Vector<char> String;
- uptr Length = 0;
};
int formatString(char *Buffer, uptr BufferLength, const char *Format, ...);
More information about the llvm-commits
mailing list