r243949 - [UB] Guard two calls to memcpy in generated attribute code to handle
Chandler Carruth
chandlerc at gmail.com
Mon Aug 3 20:53:02 PDT 2015
Author: chandlerc
Date: Mon Aug 3 22:53:01 2015
New Revision: 243949
URL: http://llvm.org/viewvc/llvm-project?rev=243949&view=rev
Log:
[UB] Guard two calls to memcpy in generated attribute code to handle
null StringRef objects as inputs.
Found by UBSan.
Modified:
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=243949&r1=243948&r2=243949&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Mon Aug 3 22:53:01 2015
@@ -326,7 +326,8 @@ namespace {
OS << " " << getLowerName() << "Length = S.size();\n";
OS << " this->" << getLowerName() << " = new (C, 1) char ["
<< getLowerName() << "Length];\n";
- OS << " std::memcpy(this->" << getLowerName() << ", S.data(), "
+ OS << " if (!S.empty())\n";
+ OS << " std::memcpy(this->" << getLowerName() << ", S.data(), "
<< getLowerName() << "Length);\n";
OS << " }";
}
@@ -337,7 +338,8 @@ namespace {
OS << "A->get" << getUpperName() << "()";
}
void writeCtorBody(raw_ostream &OS) const override {
- OS << " std::memcpy(" << getLowerName() << ", " << getUpperName()
+ OS << " if (!" << getUpperName() << ".empty())\n";
+ OS << " std::memcpy(" << getLowerName() << ", " << getUpperName()
<< ".data(), " << getLowerName() << "Length);";
}
void writeCtorInitializers(raw_ostream &OS) const override {
More information about the cfe-commits
mailing list