summaryrefslogtreecommitdiff
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorKarthik Bhat <kv.bhat@samsung.com>2014-03-27 12:08:23 +0000
committerKarthik Bhat <kv.bhat@samsung.com>2014-03-27 12:08:23 +0000
commit6ac86cf119640b71328a3530f2906a86487696c9 (patch)
treeccb887442b20799b2f739a5a83d0cbd3be4972ca /lib/Bitcode
parent0d811741fbb559de49c984efa42642cf488bb379 (diff)
downloadllvm-6ac86cf119640b71328a3530f2906a86487696c9.tar.gz
llvm-6ac86cf119640b71328a3530f2906a86487696c9.tar.bz2
llvm-6ac86cf119640b71328a3530f2906a86487696c9.tar.xz
All new elements except the last one initialized to NULL. Ideally, once parsing is complete, all elements should be non-NULL.
To safe-guard BitcodeReader, this patch adds null check for all access to these list. Patch by Dinesh Dwivedi! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204920 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index ab0a1249f2..f712d9db64 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -960,7 +960,7 @@ error_code BitcodeReader::ParseValueSymbolTable() {
if (ConvertToString(Record, 1, ValueName))
return Error(InvalidRecord);
unsigned ValueID = Record[0];
- if (ValueID >= ValueList.size())
+ if (ValueID >= ValueList.size() || !ValueList[ValueID])
return Error(InvalidRecord);
Value *V = ValueList[ValueID];
@@ -1027,7 +1027,7 @@ error_code BitcodeReader::ParseMetadata() {
unsigned Size = Record.size();
NamedMDNode *NMD = TheModule->getOrInsertNamedMetadata(Name);
for (unsigned i = 0; i != Size; ++i) {
- MDNode *MD = dyn_cast<MDNode>(MDValueList.getValueFwdRef(Record[i]));
+ MDNode *MD = dyn_cast_or_null<MDNode>(MDValueList.getValueFwdRef(Record[i]));
if (MD == 0)
return Error(InvalidRecord);
NMD->addOperand(MD);
@@ -1109,7 +1109,7 @@ error_code BitcodeReader::ResolveGlobalAndAliasInits() {
// Not ready to resolve this yet, it requires something later in the file.
GlobalInits.push_back(GlobalInitWorklist.back());
} else {
- if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
+ if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
GlobalInitWorklist.back().first->setInitializer(C);
else
return Error(ExpectedConstant);
@@ -1122,7 +1122,7 @@ error_code BitcodeReader::ResolveGlobalAndAliasInits() {
if (ValID >= ValueList.size()) {
AliasInits.push_back(AliasInitWorklist.back());
} else {
- if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
+ if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
AliasInitWorklist.back().first->setAliasee(C);
else
return Error(ExpectedConstant);
@@ -1135,7 +1135,7 @@ error_code BitcodeReader::ResolveGlobalAndAliasInits() {
if (ValID >= ValueList.size()) {
FunctionPrefixes.push_back(FunctionPrefixWorklist.back());
} else {
- if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
+ if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
FunctionPrefixWorklist.back().first->setPrefixData(C);
else
return Error(ExpectedConstant);
@@ -1195,7 +1195,7 @@ error_code BitcodeReader::ParseConstants() {
case bitc::CST_CODE_SETTYPE: // SETTYPE: [typeid]
if (Record.empty())
return Error(InvalidRecord);
- if (Record[0] >= TypeList.size())
+ if (Record[0] >= TypeList.size() || !TypeList[Record[0]])
return Error(InvalidRecord);
CurTy = TypeList[Record[0]];
continue; // Skip the ValueList manipulation.
@@ -3039,7 +3039,7 @@ OutOfRecordLoop:
if (A->getParent() == 0) {
// We found at least one unresolved value. Nuke them all to avoid leaks.
for (unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){
- if ((A = dyn_cast<Argument>(ValueList[i])) && A->getParent() == 0) {
+ if ((A = dyn_cast_or_null<Argument>(ValueList[i])) && A->getParent() == 0) {
A->replaceAllUsesWith(UndefValue::get(A->getType()));
delete A;
}