From 33fbde77f2be8b03685a891bb7fbdbc9727d2e94 Mon Sep 17 00:00:00 2001
From: Ezo <ezo.dev@gmail.com>
Date: Wed, 20 Nov 2013 03:13:47 +0000
Subject: [PATCH] Added nullptr chcking after dynamic casts
---
src/apps/debugger/arch/x86/ArchitectureX86.cpp | 8 +++++++-
src/apps/debugger/model/Type.cpp | 7 +++++--
src/apps/debugger/user_interface/gui/util/SettingsMenu.cpp | 4 +++-
src/apps/debugger/value/value_nodes/ArrayValueNode.cpp | 2 ++
src/apps/debugger/value/value_nodes/BMessageValueNode.cpp | 7 +++++++
5 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.cpp b/src/apps/debugger/arch/x86/ArchitectureX86.cpp
index b0bec17..8650dca 100644
a
|
b
|
ArchitectureX86::CreateStackFrame(Image* image, FunctionDebugInfo* function,
|
272 | 272 | CpuState*& _previousCpuState) |
273 | 273 | { |
274 | 274 | CpuStateX86* cpuState = dynamic_cast<CpuStateX86*>(_cpuState); |
| 275 | if(cpuState == NULL) |
| 276 | exit(2); |
275 | 277 | |
276 | 278 | uint32 framePointer = cpuState->IntRegisterValue(X86_REGISTER_EBP); |
277 | 279 | uint32 eip = cpuState->IntRegisterValue(X86_REGISTER_EIP); |
… |
… |
ArchitectureX86::UpdateStackFrameCpuState(const StackFrame* frame,
|
416 | 418 | // This is not a top frame, so we want to offset eip to the previous |
417 | 419 | // (calling) instruction. |
418 | 420 | CpuStateX86* cpuState = dynamic_cast<CpuStateX86*>(previousCpuState); |
419 | | |
| 421 | if(cpuState == NULL) |
| 422 | exit(2); |
| 423 | |
420 | 424 | // get eip |
421 | 425 | uint32 eip = cpuState->IntRegisterValue(X86_REGISTER_EIP); |
422 | 426 | if (previousFunction == NULL || eip <= previousFunction->Address()) |
… |
… |
ArchitectureX86::GetReturnAddressLocation(StackFrame* frame,
|
676 | 680 | } else { |
677 | 681 | ValuePieceLocation piece; |
678 | 682 | CpuStateX86* state = dynamic_cast<CpuStateX86*>(frame->GetCpuState()); |
| 683 | if(state == NULL) |
| 684 | exit(2); |
679 | 685 | piece.SetToMemory(state->IntRegisterValue(X86_REGISTER_EAX)); |
680 | 686 | piece.SetSize(valueSize); |
681 | 687 | if (!location->AddPiece(piece)) |
diff --git a/src/apps/debugger/model/Type.cpp b/src/apps/debugger/model/Type.cpp
index 318abf2..d13ae1e 100644
a
|
b
|
ArrayDimension::CountElements() const
|
44 | 44 | { |
45 | 45 | Type* type = GetType(); |
46 | 46 | |
47 | | if (type->Kind() == TYPE_ENUMERATION) |
| 47 | if (type->Kind() == TYPE_ENUMERATION) |
48 | 48 | return dynamic_cast<EnumerationType*>(type)->CountValues(); |
49 | | |
| 49 | |
50 | 50 | if (type->Kind() == TYPE_SUBRANGE) { |
51 | 51 | SubrangeType* subrangeType = dynamic_cast<SubrangeType*>(type); |
| 52 | if(subrangeType == NULL) |
| 53 | exit(2); |
| 54 | |
52 | 55 | BVariant lower = subrangeType->LowerBound(); |
53 | 56 | BVariant upper = subrangeType->UpperBound(); |
54 | 57 | bool isSigned; |
diff --git a/src/apps/debugger/user_interface/gui/util/SettingsMenu.cpp b/src/apps/debugger/user_interface/gui/util/SettingsMenu.cpp
index 6165eef..8e34705 100644
a
|
b
|
public:
|
176 | 176 | { |
177 | 177 | SettingsOption* selectedOption = settings->OptionValue( |
178 | 178 | dynamic_cast<OptionsSetting*>(GetSetting())); |
179 | | |
| 179 | if(selectedOption == NULL) |
| 180 | exit(2); |
| 181 | |
180 | 182 | for (int32 i = 0; BMenuItem* item = Submenu()->ItemAt(i); i++) { |
181 | 183 | OptionMenuItem* optionItem = dynamic_cast<OptionMenuItem*>(item); |
182 | 184 | if (optionItem != NULL) |
diff --git a/src/apps/debugger/value/value_nodes/ArrayValueNode.cpp b/src/apps/debugger/value/value_nodes/ArrayValueNode.cpp
index bc05323..061cf48 100644
a
|
b
|
ArrayValueNodeChild::ResolveLocation(ValueLoader* valueLoader,
|
315 | 315 | |
316 | 316 | child = dynamic_cast<AbstractArrayValueNodeChild*>( |
317 | 317 | child->ArrayParent()->NodeChild()); |
| 318 | if(child == NULL) |
| 319 | exit(2); |
318 | 320 | } |
319 | 321 | |
320 | 322 | // resolve the element location |
diff --git a/src/apps/debugger/value/value_nodes/BMessageValueNode.cpp b/src/apps/debugger/value/value_nodes/BMessageValueNode.cpp
index 0da34fe..165a504 100644
a
|
b
|
public:
|
70 | 70 | ValueLocation* parentLocation = fParent->Location(); |
71 | 71 | ValueLocation* location; |
72 | 72 | CompoundType* type = dynamic_cast<CompoundType*>(fParent->GetType()); |
| 73 | if(type == NULL) |
| 74 | exit(2); |
73 | 75 | status_t error = B_OK; |
74 | 76 | if (fParent->fIsFlatMessage) { |
75 | 77 | location = new ValueLocation(); |
… |
… |
BMessageValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
|
175 | 177 | BVariant what; |
176 | 178 | |
177 | 179 | CompoundType* baseType = dynamic_cast<CompoundType*>(fType); |
| 180 | if(baseType == NULL) |
| 181 | exit(2); |
178 | 182 | |
179 | 183 | if (fIsFlatMessage) { |
180 | 184 | headerAddress.SetTo(location->PieceAt(0).address); |
… |
… |
BMessageValueNode::CreateChildren()
|
334 | 338 | { |
335 | 339 | DataMember* member = NULL; |
336 | 340 | CompoundType* messageType = dynamic_cast<CompoundType*>(fType); |
| 341 | if(messageType == NULL) |
| 342 | exit(2); |
| 343 | |
337 | 344 | for (int32 i = 0; i < messageType->CountDataMembers(); i++) { |
338 | 345 | member = messageType->DataMemberAt(i); |
339 | 346 | if (strcmp(member->Name(), "what") == 0) { |