CID 1273599: null dereference in SATGroup

And some additional style fixes.
This commit is contained in:
Philippe Saint-Pierre
2015-06-24 18:58:28 -04:00
parent e3e5e00627
commit f0b2d33bcf
+27 -38
View File
@@ -68,7 +68,7 @@ WindowArea::Init(SATGroup* group)
{ {
_UninitConstraints(); _UninitConstraints();
if (group != NULL && group->fWindowAreaList.AddItem(this) == false) if (group == NULL || group->fWindowAreaList.AddItem(this) == false)
return false; return false;
fGroup = group; fGroup = group;
@@ -821,37 +821,37 @@ SATGroup::AddWindow(SATWindow* window, Tab* left, Tab* top, Tab* right,
BReference<Tab> leftRef, rightRef, topRef, bottomRef; BReference<Tab> leftRef, rightRef, topRef, bottomRef;
BReference<Crossing> leftTopRef, rightTopRef, leftBottomRef, rightBottomRef; BReference<Crossing> leftTopRef, rightTopRef, leftBottomRef, rightBottomRef;
if (left && top) if (left != NULL && top != NULL)
leftTopRef = left->FindCrossing(top); leftTopRef = left->FindCrossing(top);
if (right && top) if (right != NULL && top != NULL)
rightTopRef = right->FindCrossing(top); rightTopRef = right->FindCrossing(top);
if (left && bottom) if (left != NULL && bottom != NULL)
leftBottomRef = left->FindCrossing(bottom); leftBottomRef = left->FindCrossing(bottom);
if (right && bottom) if (right != NULL && bottom != NULL)
rightBottomRef = right->FindCrossing(bottom); rightBottomRef = right->FindCrossing(bottom);
if (!left) { if (left == NULL) {
leftRef = _AddVerticalTab(); leftRef = _AddVerticalTab();
left = leftRef.Get(); left = leftRef.Get();
} }
if (!top) { if (top == NULL) {
topRef = _AddHorizontalTab(); topRef = _AddHorizontalTab();
top = topRef.Get(); top = topRef.Get();
} }
if (!right) { if (right == NULL) {
rightRef = _AddVerticalTab(); rightRef = _AddVerticalTab();
right = rightRef.Get(); right = rightRef.Get();
} }
if (!bottom) { if (bottom == NULL) {
bottomRef = _AddHorizontalTab(); bottomRef = _AddHorizontalTab();
bottom = bottomRef.Get(); bottom = bottomRef.Get();
} }
if (!left || !top || !right || !bottom) if (left == NULL || top == NULL || right == NULL || bottom == NULL)
return false; return false;
if (!leftTopRef) { if (leftTopRef == NULL) {
leftTopRef = left->AddCrossing(top); leftTopRef = left->AddCrossing(top);
if (!leftTopRef) if (leftTopRef == NULL)
return false; return false;
} }
if (!rightTopRef) { if (!rightTopRef) {
@@ -872,7 +872,7 @@ SATGroup::AddWindow(SATWindow* window, Tab* left, Tab* top, Tab* right,
WindowArea* area = new(std::nothrow) WindowArea(leftTopRef, rightTopRef, WindowArea* area = new(std::nothrow) WindowArea(leftTopRef, rightTopRef,
leftBottomRef, rightBottomRef); leftBottomRef, rightBottomRef);
if (!area) if (area == NULL)
return false; return false;
// the area register itself in our area list // the area register itself in our area list
if (area->Init(this) == false) { if (area->Init(this) == false) {
@@ -932,7 +932,7 @@ int32
SATGroup::CountItems() SATGroup::CountItems()
{ {
return fSATWindowList.CountItems(); return fSATWindowList.CountItems();
}; }
SATWindow* SATWindow*
@@ -1004,7 +1004,7 @@ SATGroup::RestoreGroup(const BMessage& archive, StackAndTile* sat)
{ {
// create new group // create new group
SATGroup* group = new (std::nothrow)SATGroup; SATGroup* group = new (std::nothrow)SATGroup;
if (!group) if (group == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
BReference<SATGroup> groupRef; BReference<SATGroup> groupRef;
groupRef.SetTo(group, true); groupRef.SetTo(group, true);
@@ -1189,7 +1189,7 @@ void
SATGroup::_SplitGroupIfNecessary(WindowArea* removedArea) SATGroup::_SplitGroupIfNecessary(WindowArea* removedArea)
{ {
// if there are windows stacked in the area we don't need to split // if there are windows stacked in the area we don't need to split
if (!removedArea || removedArea->WindowList().CountItems() > 1) if (removedArea == NULL || removedArea->WindowList().CountItems() > 1)
return; return;
WindowAreaList neighbourWindows; WindowAreaList neighbourWindows;
@@ -1361,8 +1361,7 @@ SATGroup::_FollowSeed(WindowArea* area, WindowArea* veto,
newGroup.AddItem(currentArea); newGroup.AddItem(currentArea);
// if we get a area from the seed list it is not a seed any more // if we get a area from the seed list it is not a seed any more
seedList.RemoveItem(currentArea); seedList.RemoveItem(currentArea);
} } else {
else {
// don't _FollowSeed of invalid areas // don't _FollowSeed of invalid areas
neighbours.RemoveItemAt(i); neighbours.RemoveItemAt(i);
i--; i--;
@@ -1379,7 +1378,7 @@ SATGroup::_SpawnNewGroup(const WindowAreaList& newGroup)
{ {
STRACE_SAT("SATGroup::_SpawnNewGroup\n"); STRACE_SAT("SATGroup::_SpawnNewGroup\n");
SATGroup* group = new (std::nothrow)SATGroup; SATGroup* group = new (std::nothrow)SATGroup;
if (!group) if (group == NULL)
return; return;
BReference<SATGroup> groupRef; BReference<SATGroup> groupRef;
groupRef.SetTo(group, true); groupRef.SetTo(group, true);
@@ -1399,15 +1398,12 @@ void
SATGroup::_EnsureGroupIsOnScreen(SATGroup* group) SATGroup::_EnsureGroupIsOnScreen(SATGroup* group)
{ {
STRACE_SAT("SATGroup::_EnsureGroupIsOnScreen\n"); STRACE_SAT("SATGroup::_EnsureGroupIsOnScreen\n");
if (!group) if (group == NULL || group->CountItems() < 1)
return;
if (group->CountItems() < 1)
return; return;
SATWindow* window = group->WindowAt(0); SATWindow* window = group->WindowAt(0);
Desktop* desktop = window->GetWindow()->Desktop(); Desktop* desktop = window->GetWindow()->Desktop();
if (!desktop) if (desktop == NULL)
return; return;
const float kBigDistance = 1E+10; const float kBigDistance = 1E+10;
@@ -1436,8 +1432,7 @@ SATGroup::_EnsureGroupIsOnScreen(SATGroup* group)
if (dist < minLeftDistance) { if (dist < minLeftDistance) {
minLeftDistance = dist; minLeftDistance = dist;
leftRect = frame; leftRect = frame;
} } else if (dist == minLeftDistance)
else if (dist == minLeftDistance)
leftRect = leftRect | frame; leftRect = leftRect | frame;
} }
if (frame.top > screen.bottom - kMinOverlap) { if (frame.top > screen.bottom - kMinOverlap) {
@@ -1445,8 +1440,7 @@ SATGroup::_EnsureGroupIsOnScreen(SATGroup* group)
if (dist < minBottomDistance) { if (dist < minBottomDistance) {
minBottomDistance = dist; minBottomDistance = dist;
bottomRect = frame; bottomRect = frame;
} } else if (dist == minBottomDistance)
else if (dist == minBottomDistance)
bottomRect = bottomRect | frame; bottomRect = bottomRect | frame;
} }
if (frame.left > screen.right - kMinOverlap) { if (frame.left > screen.right - kMinOverlap) {
@@ -1454,8 +1448,7 @@ SATGroup::_EnsureGroupIsOnScreen(SATGroup* group)
if (dist < minRightDistance) { if (dist < minRightDistance) {
minRightDistance = dist; minRightDistance = dist;
rightRect = frame; rightRect = frame;
} } else if (dist == minRightDistance)
else if (dist == minRightDistance)
rightRect = rightRect | frame; rightRect = rightRect | frame;
} }
if (frame.bottom < screen.top + kMinOverlap) { if (frame.bottom < screen.top + kMinOverlap) {
@@ -1463,8 +1456,7 @@ SATGroup::_EnsureGroupIsOnScreen(SATGroup* group)
if (dist < minTopDistance) { if (dist < minTopDistance) {
minTopDistance = dist; minTopDistance = dist;
topRect = frame; topRect = frame;
} } else if (dist == minTopDistance)
else if (dist == minTopDistance)
topRect = topRect | frame; topRect = topRect | frame;
} }
} }
@@ -1473,16 +1465,13 @@ SATGroup::_EnsureGroupIsOnScreen(SATGroup* group)
if (minLeftDistance < kBigDistance) { if (minLeftDistance < kBigDistance) {
offset.x = screen.left - leftRect.right + kMoveToScreen; offset.x = screen.left - leftRect.right + kMoveToScreen;
_CallculateYOffset(offset, leftRect, screen); _CallculateYOffset(offset, leftRect, screen);
} } else if (minTopDistance < kBigDistance) {
else if (minTopDistance < kBigDistance) {
offset.y = screen.top - topRect.bottom + kMoveToScreen; offset.y = screen.top - topRect.bottom + kMoveToScreen;
_CallculateXOffset(offset, topRect, screen); _CallculateXOffset(offset, topRect, screen);
} } else if (minRightDistance < kBigDistance) {
else if (minRightDistance < kBigDistance) {
offset.x = screen.right - rightRect.left - kMoveToScreen; offset.x = screen.right - rightRect.left - kMoveToScreen;
_CallculateYOffset(offset, rightRect, screen); _CallculateYOffset(offset, rightRect, screen);
} } else if (minBottomDistance < kBigDistance) {
else if (minBottomDistance < kBigDistance) {
offset.y = screen.bottom - bottomRect.top - kMoveToScreen; offset.y = screen.bottom - bottomRect.top - kMoveToScreen;
_CallculateXOffset(offset, bottomRect, screen); _CallculateXOffset(offset, bottomRect, screen);
} }