ramfs: Correct usage of Nodes in Entry.

* We do not want to set fNode in the constructor but let the invocation
   of Link() take care of doing so instead.

 * Link/Unlink manipulate linked-lists. Thus it is dangerous to use them
   in tandem on the same Node object. Add a check for this.

 * Minor cleanup.
This commit is contained in:
Augustin Cavalier 2022-11-30 00:17:58 -05:00
parent 8426404f97
commit 6a8bb0562e

View File

@ -13,7 +13,7 @@
// constructor
Entry::Entry(const char *name, Node *node, Directory *parent)
: fParent(parent),
fNode(node),
fNode(NULL),
fName(name),
fReferrerLink(),
fIterators()
@ -40,18 +40,19 @@ Entry::InitCheck() const
status_t
Entry::Link(Node *node)
{
status_t error = (node ? B_OK : B_BAD_VALUE);
if (error == B_OK) {
// We first link to the new node and then unlink the old one. So, no
// harm is done, if both are the same.
if (node == NULL)
return B_BAD_VALUE;
if (node == fNode)
return B_OK;
// We first link to the new node and then unlink the old one.
Node *oldNode = fNode;
error = node->Link(this);
status_t error = node->Link(this);
if (error == B_OK) {
fNode = node;
if (oldNode)
oldNode->Unlink(this);
}
}
return error;
}
@ -101,4 +102,3 @@ Entry::GetAllocationInfo(AllocationInfo &info)
info.AddStringAllocation(fName.GetLength());
fNode->GetAllocationInfo(info);
}