Skip to content

Commit

Permalink
Fix crashes caused by unknown item handles
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Oct 12, 2017
1 parent 9a2fcab commit 633a1c0
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 93 deletions.
18 changes: 10 additions & 8 deletions src/FileTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ unsigned char *CFileTable::GetHandleByPath(const char *path)
return node->data.handle;
}

std::string CFileTable::GetPathByHandle(unsigned char *handle)
bool CFileTable::GetPathByHandle(unsigned char *handle, std::string &path)
{
unsigned int id;
tree_node_<FILE_ITEM>* node;

id = *(unsigned int *)handle;
// TODO : Not found item

node = GetItemByID(id);
if (node != NULL) {
return g_FileTree.GetNodeFullPath(node);
g_FileTree.GetNodeFullPath(node, path);
return true;
} else {
return NULL;
return false;
}
//return pItem == NULL ? NULL : pItem->path;
}

tree_node_<FILE_ITEM>* CFileTable::FindItemByPath(const char *path)
Expand Down Expand Up @@ -317,7 +317,9 @@ bool CFileTable::RemoveItem(const char *path) {
}
// Remove from table end

g_FileTree.RemoveItem(g_FileTree.GetNodeFullPath(foundDeletedItem).c_str());
std::string path;
g_FileTree.GetNodeFullPath(foundDeletedItem, path);
g_FileTree.RemoveItem(path.c_str());
return true;
}
else {
Expand Down Expand Up @@ -364,9 +366,9 @@ unsigned char *GetFileHandle(const char *path)
return g_FileTable.GetHandleByPath(path);
}

std::string GetFilePath(unsigned char *handle)
bool GetFilePath(unsigned char *handle, std::string &filePath)
{
return g_FileTable.GetPathByHandle(handle);
return g_FileTable.GetPathByHandle(handle, filePath);
}

int RenameFile(const char *pathFrom, const char *pathTo)
Expand Down
4 changes: 2 additions & 2 deletions src/FileTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CFileTable
~CFileTable();
unsigned long GetIDByPath(const char *path);
unsigned char *GetHandleByPath(const char *path);
std::string GetPathByHandle(unsigned char *handle);
bool GetPathByHandle(unsigned char *handle, std::string &path);
tree_node_<FILE_ITEM>* FindItemByPath(const char *path);
bool RemoveItem(const char *path);
void RenameFile(const char *pathFrom, const char *pathTo);
Expand All @@ -53,7 +53,7 @@ class CFileTable
extern bool FileExists(const char *path);
extern unsigned long GetFileID(const char *path);
extern unsigned char *GetFileHandle(const char *path);
extern std::string GetFilePath(unsigned char *handle);
extern bool GetFilePath(unsigned char *handle, std::string &filePath);
extern int RenameFile(const char *pathFrom, const char *pathTo);
extern int RenameDirectory(const char *pathFrom, const char *pathTo);
extern int RemoveFolder(const char *path);
Expand Down
5 changes: 1 addition & 4 deletions src/FileTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,8 @@ tree_node_<FILE_ITEM>* CFileTree::findParentNodeFromRootForPath(const char *path
}
}

std::string CFileTree::GetNodeFullPath(tree_node_<FILE_ITEM>* node)
void CFileTree::GetNodeFullPath(tree_node_<FILE_ITEM>* node, std::string &path)
{
std::string path;
path.append(node->data.path);
tree_node_<FILE_ITEM>* parentNode = node->parent;
while (parentNode != NULL)
Expand All @@ -280,8 +279,6 @@ std::string CFileTree::GetNodeFullPath(tree_node_<FILE_ITEM>* node)
path.insert(0, parentNode->data.path);
parentNode = parentNode->parent;
}

return path;
}

void DisplayTree(tree_node_<FILE_ITEM>* node, int level)
Expand Down
2 changes: 1 addition & 1 deletion src/FileTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CFileTree

tree_node_<FILE_ITEM>* FindFileItemForPath(const char *absolutePath);

std::string GetNodeFullPath(tree_node_<FILE_ITEM>* node);
void GetNodeFullPath(tree_node_<FILE_ITEM>* node, std::string &fullPath);

protected:
tree_node_<FILE_ITEM>* findNodeFromRootWithPath(const char *path);
Expand Down
Loading

0 comments on commit 633a1c0

Please sign in to comment.