[cfe-commits] r161780 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/CodeGen/ms-inline-asm.c

Chad Rosier mcrosier at apple.com
Mon Aug 13 14:16:22 PDT 2012


Hi Dmitri,
Sorry about that, this is still somewhat unfamiliar territory..  Is this what you're suggesting?

Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp	(revision 161780)
+++ lib/Sema/SemaStmt.cpp	(working copy)
@@ -2835,11 +2835,8 @@
         SmallString<32> TokenBuf;
         TokenBuf.resize(32);
         bool StringInvalid = false;
-        const char *ThisTokBuf = &TokenBuf[0];
-        unsigned ThisTokLen =
-          Lexer::getSpelling(AsmToks[j], ThisTokBuf, SemaRef.getSourceManager(),
-                             SemaRef.getLangOpts(), &StringInvalid);
-        Asm += StringRef(ThisTokBuf, ThisTokLen);
+        Asm += SemaRef.PP.getSpelling(AsmToks[j], TokenBuf, &StringInvalid);
+        assert (!StringInvalid && "Expected valid string!");
         break;
       }

Should I increase the size of the buffer?

 Chad

On Aug 13, 2012, at 1:55 PM, Dmitri Gribenko wrote:

> On Mon, Aug 13, 2012 at 1:32 PM, Chad Rosier <mcrosier at apple.com> wrote:
>> +      case tok::numeric_constant: {
>> +        SmallString<32> TokenBuf;
>> +        TokenBuf.resize(32);
>> +        bool StringInvalid = false;
>> +        const char *ThisTokBuf = &TokenBuf[0];
>> +        unsigned ThisTokLen =
>> +          Lexer::getSpelling(AsmToks[j], ThisTokBuf, SemaRef.getSourceManager(),
>> +                             SemaRef.getLangOpts(), &StringInvalid);
>> +        Asm += StringRef(ThisTokBuf, ThisTokLen);
>>         break;
>>       }
> 
> This sounds like a buffer overflow...  It would be better to use
> another Lexer::getSpelling() overload that returns StringRef.  Or you
> could use Preprocessor::getSpelling().
> 
> Dmitri
> 
> -- 
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/




More information about the cfe-commits mailing list