From 88552afbb4b41b6f859e7051cc0e4b0efbecea78 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Sat, 18 Aug 2018 22:30:12 +0200 Subject: Fix some possible errors --- src/cc4group.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cc4group.c b/src/cc4group.c index 89593b4..199dcdc 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -1,7 +1,9 @@ // TODO? Error handling of lists? #define _POSIX_C_SOURCE 200809L +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include "cc4group.h" #include "c4groupheader.h" @@ -470,7 +472,7 @@ static void cc4group_uncompressGroup(CC4Group* const this) goto ret; } - C4GroupEntryCore* cores = (C4GroupEntryCore*)((void*)(header) + sizeof(C4GroupHeader)); + C4GroupEntryCore* cores = (C4GroupEntryCore*)((uint8_t*)(header) + sizeof(C4GroupHeader)); strm.next_out = (Bytef*)cores; strm.avail_out = sizeof(C4GroupEntryCore) * header->Entries; @@ -489,7 +491,7 @@ static void cc4group_uncompressGroup(CC4Group* const this) mappedTmpFile = cc4group_tmpMemoryStrategy(this, currentSize, &tmpCleanup); - uint8_t* data = (void*)(mappedTmpFile) + sizeof(C4GroupHeader) + sizeof(C4GroupEntryCore) * header->Entries; + uint8_t* data = (uint8_t*)(mappedTmpFile) + sizeof(C4GroupHeader) + sizeof(C4GroupEntryCore) * header->Entries; // write alredy decompressed header and cores into the file memcpy(mappedTmpFile, header, data - mappedTmpFile); @@ -1292,7 +1294,7 @@ static bool cc4group_getEntryInfos(CC4Group* const this, const char* const path, } // returns the child path and stores the parentPath in parentPath; modifies combinedPath -static char* cc4group_splitParentAndChildPaths(char* const combinedPath, char** const parentPath) +static char* cc4group_splitParentAndChildPaths(char* const combinedPath, const char** const parentPath) { char* slash = strrchr(combinedPath, '/'); @@ -1314,7 +1316,7 @@ static bool cc4group_getParentAndChildEntries(CC4Group* const this, const char* const C4GroupEntryData* parent; char* myPath = strdup(path); - char* parentPath; + const char* parentPath; char* entryName = cc4group_splitParentAndChildPaths(myPath, &parentPath); parent = cc4group_getEntryByPath(this, parentPath); @@ -1379,9 +1381,8 @@ static bool cc4group_deleteEntry(CC4Group* const this, const char* const path, b return true; } -static C4GroupEntryData* cc4group_addEntryToDirectory(CC4Group* const this, C4GroupEntryData* const directory, const C4GroupEntryData* const entry) +static C4GroupEntryData* cc4group_addEntryToDirectory(C4GroupEntryData* const directory, const C4GroupEntryData* const entry) { - assert(this); assert(directory->core.Directory); // TODO? Implement engine-optimized order sorting here? @@ -1413,7 +1414,7 @@ static bool cc4group_renameEntry(CC4Group* const this, const char* const oldPath } char* targetPath = strdup(newPath); - char* targetDirectory; + const char* targetDirectory; char* targetName = cc4group_splitParentAndChildPaths(targetPath, &targetDirectory); C4GroupEntryData* newParent = (C4GroupEntryData*)cc4group_getEntryByPath(this, targetDirectory); @@ -1425,7 +1426,7 @@ static bool cc4group_renameEntry(CC4Group* const this, const char* const oldPath } C4GroupEntryCore_setFileName(&entry->value.core, targetName); - cc4group_addEntryToDirectory(this, newParent, &entry->value); + cc4group_addEntryToDirectory(newParent, &entry->value); GroupEntryListRemove(oldParent->children, entry); free(targetPath); @@ -1441,7 +1442,7 @@ static C4GroupEntryData* cc4group_createEntry(CC4Group* const this, const char* } char* targetPath = strdup(path); - char* targetDirectory; + const char* targetDirectory; char* targetName = cc4group_splitParentAndChildPaths(targetPath, &targetDirectory); C4GroupEntryData* parent = (C4GroupEntryData*)cc4group_getEntryByPath(this, targetDirectory); @@ -1469,7 +1470,7 @@ static C4GroupEntryData* cc4group_createEntry(CC4Group* const this, const char* free(targetPath); - return cc4group_addEntryToDirectory(this, parent, &entry); + return cc4group_addEntryToDirectory(parent, &entry); } static bool cc4group_createDirectory(CC4Group* const this, const char* const path) -- cgit v1.2.3-54-g00ecf