diff options
author | Evan Cheng <evan.cheng@apple.com> | 2010-09-24 05:18:35 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2010-09-24 05:18:35 +0000 |
commit | 40a42229966507e6328da0ab7b6d7781a68ccb0f (patch) | |
tree | a62347134e57e95a44dc746a81e377fa74f07a16 /llvm/lib/Target/ARM/ARMConstantPoolValue.cpp | |
parent | 0fffff581665b768d100eece196e59b00eb16e7e (diff) | |
download | bcm5719-llvm-40a42229966507e6328da0ab7b6d7781a68ccb0f.tar.gz bcm5719-llvm-40a42229966507e6328da0ab7b6d7781a68ccb0f.zip |
Fix a potential null dereference bug.
llvm-svn: 114723
Diffstat (limited to 'llvm/lib/Target/ARM/ARMConstantPoolValue.cpp')
-rw-r--r-- | llvm/lib/Target/ARM/ARMConstantPoolValue.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp b/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp index f13ccc63844..4ee71e24a7b 100644 --- a/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp @@ -53,6 +53,14 @@ const BlockAddress *ARMConstantPoolValue::getBlockAddress() const { return dyn_cast_or_null<BlockAddress>(CVal); } +static bool CPV_streq(const char *S1, const char *S2) { + if (S1 == S2) + return true; + if (S1 && S2 && strcmp(S1, S2) == 0) + return true; + return false; +} + int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) { unsigned AlignMask = Alignment - 1; @@ -65,8 +73,8 @@ int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP, if (CPV->CVal == CVal && CPV->LabelId == LabelId && CPV->PCAdjust == PCAdjust && - (CPV->S == S || strcmp(CPV->S, S) == 0) && - (CPV->Modifier == Modifier || strcmp(CPV->Modifier, Modifier) == 0)) + CPV_streq(CPV->S, S) && + CPV_streq(CPV->Modifier, Modifier)) return i; } } @@ -91,8 +99,8 @@ ARMConstantPoolValue::hasSameValue(ARMConstantPoolValue *ACPV) { if (ACPV->Kind == Kind && ACPV->CVal == CVal && ACPV->PCAdjust == PCAdjust && - (ACPV->S == S || strcmp(ACPV->S, S) == 0) && - (ACPV->Modifier == Modifier || strcmp(ACPV->Modifier, Modifier) == 0)) { + CPV_streq(ACPV->S, S) && + CPV_streq(ACPV->Modifier, Modifier)) { if (ACPV->LabelId == LabelId) return true; // Two PC relative constpool entries containing the same GV address or |