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

View File

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