[cfe-commits] r72621 - /cfe/trunk/lib/AST/ExprConstant.cpp

Mike Stump mrs at apple.com
Sat May 30 07:43:19 PDT 2009


Author: mrs
Date: Sat May 30 09:43:18 2009
New Revision: 72621

URL: http://llvm.org/viewvc/llvm-project?rev=72621&view=rev
Log:
Cleqnup ideas from Chris, thanks.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=72621&r1=72620&r2=72621&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat May 30 09:43:18 2009
@@ -17,6 +17,7 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Compiler.h"
 #include <cstring>
 
@@ -1320,13 +1321,13 @@
       if (!S->isWide()) {
         const llvm::fltSemantics &Sem =
           Info.Ctx.getFloatTypeSemantics(E->getType());
-        char *s = (char *)malloc (S->getByteLength()+1);
-        memcpy(s,  S->getStrData(), S->getByteLength());
-        s[S->getByteLength()] = 0;
+        llvm::SmallString<16> s;
+        s.append(S->getStrData(), S->getStrData() + S->getByteLength());
+        s += '\0';
         long l;
         char *endp;
-        l = strtol(S->getStrData(), &endp, 0);
-        if (endp != (S->getStrData() + S->getByteLength()))
+        l = strtol(&s[0], &endp, 0);
+        if (endp != s.end()-1)
           return false;
         unsigned type = (unsigned int)l;;
         Result = llvm::APFloat::getNaN(Sem, false, type);





More information about the cfe-commits mailing list