jgorbe created this revision.
jgorbe added reviewers: clayborg, zturner.
Herald added a subscriber: jdoerfert.
The copy constructor of RegularExpression doesn't initialize m_comp_err. This
causes an use-of-initialized-value error when a RegularExpression is copied:
the copy constructor calls Compile, which calls Free to free the existing regex
if needed, which in turn reads m_comp_err to check if there's any regex to be
freed.
This change calls the default constructor from the other constructors to make
sure members are always initialized with sensible values. This also avoids
duplicating init logic, like the `RegularExpression(llvm:StringRef)`
constructor does, which is error prone.
https://reviews.llvm.org/D62334
Files:
lldb/source/Utility/RegularExpression.cpp
Index: lldb/source/Utility/RegularExpression.cpp
===================================================================
--- lldb/source/Utility/RegularExpression.cpp
+++ lldb/source/Utility/RegularExpression.cpp
@@ -29,13 +29,12 @@
// Constructor that compiles "re" using "flags" and stores the resulting
// compiled regular expression into this object.
RegularExpression::RegularExpression(llvm::StringRef str)
- : m_re(), m_comp_err(1), m_preg() {
- memset(&m_preg, 0, sizeof(m_preg));
+ : RegularExpression() {
Compile(str);
}
-RegularExpression::RegularExpression(const RegularExpression &rhs) {
- memset(&m_preg, 0, sizeof(m_preg));
+RegularExpression::RegularExpression(const RegularExpression &rhs)
+ : RegularExpression() {
Compile(rhs.GetText());
}
Index: lldb/source/Utility/RegularExpression.cpp
===================================================================
--- lldb/source/Utility/RegularExpression.cpp
+++ lldb/source/Utility/RegularExpression.cpp
@@ -29,13 +29,12 @@
// Constructor that compiles "re" using "flags" and stores the resulting
// compiled regular expression into this object.
RegularExpression::RegularExpression(llvm::StringRef str)
- : m_re(), m_comp_err(1), m_preg() {
- memset(&m_preg, 0, sizeof(m_preg));
+ : RegularExpression() {
Compile(str);
}
-RegularExpression::RegularExpression(const RegularExpression &rhs) {
- memset(&m_preg, 0, sizeof(m_preg));
+RegularExpression::RegularExpression(const RegularExpression &rhs)
+ : RegularExpression() {
Compile(rhs.GetText());
}
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits