summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-10-24 00:16:42 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-10-24 00:16:42 +0000
commitaa9894c583bc154f0cdb63cef92e542c03d24e27 (patch)
treefdbf05d12f41119a33499bea232704e4e8ef4f96 /clang/lib/AST
parent205baf61c402a7ee190be99c29e655d3066e9c38 (diff)
downloadbcm5719-llvm-aa9894c583bc154f0cdb63cef92e542c03d24e27.tar.gz
bcm5719-llvm-aa9894c583bc154f0cdb63cef92e542c03d24e27.zip
Make the local buffer overflow safe.
llvm-svn: 84981
Diffstat (limited to 'clang/lib/AST')
-rw-r--r--clang/lib/AST/ASTContext.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e226f28c867..eb09d9ecce0 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2854,11 +2854,10 @@ QualType ASTContext::BuildByRefType(const char *DeclName, QualType Ty) {
bool HasCopyAndDispose = BlockRequiresCopying(Ty);
// FIXME: Move up
- static int UniqueBlockByRefTypeID = 0;
- // FIXME. This is error prone. Luckinly stack-canary stuff caught it.
- char Name[128];
+ static unsigned int UniqueBlockByRefTypeID = 0;
+ char * Name =
+ (char*)alloca(strlen("__Block_byref_") + 10 + 1 + strlen(DeclName) + 1);
sprintf(Name, "__Block_byref_%d_%s", ++UniqueBlockByRefTypeID, DeclName);
- assert((strlen(Name) < sizeof(Name)) && "BuildByRefType - buffer overflow");
RecordDecl *T;
T = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
&Idents.get(Name));
@@ -2905,11 +2904,10 @@ QualType ASTContext::getBlockParmType(
bool BlockHasCopyDispose,
llvm::SmallVector<const Expr *, 8> &BlockDeclRefDecls) {
// FIXME: Move up
- static int UniqueBlockParmTypeID = 0;
- // FIXME. This is error prone. Luckinly stack-canary stuff caught it.
- char Name[128];
+ static unsigned int UniqueBlockParmTypeID = 0;
+ char * Name =
+ (char*)alloca(strlen("__block_literal_") + 10 + 1);
sprintf(Name, "__block_literal_%u", ++UniqueBlockParmTypeID);
- assert((strlen(Name) < sizeof(Name)) && "getBlockParmType - buffer overflow");
RecordDecl *T;
T = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
&Idents.get(Name));
OpenPOWER on IntegriCloud