]> granicus.if.org Git - clang/commitdiff
[ms-inline asm] Address a potential buffer overflow.
authorChad Rosier <mcrosier@apple.com>
Tue, 14 Aug 2012 21:48:01 +0000 (21:48 +0000)
committerChad Rosier <mcrosier@apple.com>
Tue, 14 Aug 2012 21:48:01 +0000 (21:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161896 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp

index 89f68e3237de542c7af39223c9fccb56f6d2953e..febcdc94413a01915bfedaee4847941dd2ba0c6f 100644 (file)
@@ -2870,15 +2870,12 @@ static std::string buildMSAsmString(Sema &SemaRef,
   TokenBuf.resize(512);
   unsigned AsmLineNum = 0;
   for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) {
-    const char *ThisTokBuf = &TokenBuf[0];
     bool StringInvalid = false;
-    unsigned ThisTokLen =
-      Lexer::getSpelling(AsmToks[i], ThisTokBuf, SemaRef.getSourceManager(),
-                         SemaRef.getLangOpts(), &StringInvalid);
     if (i && (!AsmLineNum || i != LineEnds[AsmLineNum-1]) &&
         needSpaceAsmToken(AsmToks[i]))
       Asm += ' ';
-    Asm += StringRef(ThisTokBuf, ThisTokLen);
+    Asm += SemaRef.PP.getSpelling(AsmToks[i], TokenBuf, &StringInvalid);
+    assert (!StringInvalid && "Expected valid string!");
     if (i + 1 == LineEnds[AsmLineNum] && i + 1 != AsmToks.size()) {
       Asm += '\n';
       ++AsmLineNum;