[Untested] fixed the compiler/linter options and fixed the corresponding code.

the code fixes have not been tested. some are trivial orthers might be a bit worrying.
This commit is contained in:
Marc
2022-10-05 13:55:04 +02:00
parent 561a2a90b8
commit 635b1adcaf
11 changed files with 40 additions and 35 deletions
+3 -3
View File
@@ -4,9 +4,9 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
endif() endif()
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Werror -fsanitize=address") set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -fsanitize=address -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wno-pointer-arith")
set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_C_FLAGS_DEBUG "-g -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "-O2") set(CMAKE_C_FLAGS_RELEASE "-O2")
# generate the compile_commands for vscode / clang # generate the compile_commands for vscode / clang
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
+6 -4
View File
@@ -26,10 +26,12 @@ int copy(const char * path, const char * dest, u_int32_t flags) {
return -1; return -1;
} }
//flags + cp + path + dest //flags + cp + path + dest
const char * args[flagCount + 4]; char * args[flagCount + 4];
args[0] = "/bin/cp"; args[0] = "/bin/cp";
args[1] = path; args[1] = alloca((strlen(path) + 1) * sizeof(char));
args[2] = dest; strcpy(args[1], path);
args[2] = alloca((strlen(dest) + 1) * sizeof(char));
strcpy(args[2], dest);
int argIndex = 3; int argIndex = 3;
if(flags & CP_LINK) { if(flags & CP_LINK) {
@@ -50,7 +52,7 @@ int copy(const char * path, const char * dest, u_int32_t flags) {
int pid = fork(); int pid = fork();
if(pid == 0) { if(pid == 0) {
//discard the const. since we are in a fork we don't care. //discard the const. since we are in a fork we don't care.
execv("/bin/cp", (char **)args); execv("/bin/cp", args);
return 0; return 0;
} else { } else {
int returnValue; int returnValue;
+3 -3
View File
@@ -21,7 +21,7 @@ static int getInputCount(const char * input) {
int elementCount = 0; int elementCount = 0;
bool prevWasValue = false; bool prevWasValue = false;
for(int i = 0; input + i != NULL && input[i] != '\0' && input[i] != '\n'; i++) { for(int i = 0; input[i] != '\0' && input[i] != '\n'; i++) {
buff[0] = input[i]; buff[0] = input[i];
//if the character is a valid character //if the character is a valid character
@@ -156,7 +156,7 @@ GList * processCondFiles(const FOMod_t * fomod, GList * flagList, GList * pendin
bool areAllFlagsValid = true; bool areAllFlagsValid = true;
//checking if all flags are valid //checking if all flags are valid
for(int flagId = 0; flagId < condFile->flagCount; flagId++) { for(long flagId = 0; flagId < condFile->flagCount; flagId++) {
const GList * link = g_list_find_custom(flagList, &(condFile->requiredFlags[flagId]), (GCompareFunc)flagEqual); const GList * link = g_list_find_custom(flagList, &(condFile->requiredFlags[flagId]), (GCompareFunc)flagEqual);
if(link == NULL) { if(link == NULL) {
areAllFlagsValid = false; areAllFlagsValid = false;
@@ -165,7 +165,7 @@ GList * processCondFiles(const FOMod_t * fomod, GList * flagList, GList * pendin
} }
if(areAllFlagsValid) { if(areAllFlagsValid) {
for(int fileId = 0; fileId < condFile->flagCount; fileId++) { for(long fileId = 0; fileId < condFile->flagCount; fileId++) {
const FOModFile_t * file = &(condFile->files[fileId]); const FOModFile_t * file = &(condFile->files[fileId]);
FOModFile_t * fileCopy = malloc(sizeof(*file)); FOModFile_t * fileCopy = malloc(sizeof(*file));
-1
View File
@@ -90,7 +90,6 @@ static int parseConditionFlags(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
} }
static int parseGroupFiles(FOModPlugin_t * plugin, xmlNodePtr nodeElement) { static int parseGroupFiles(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
FOModFile_t * files = NULL;
xmlNodePtr fileNode = nodeElement->children; xmlNodePtr fileNode = nodeElement->children;
while(fileNode != NULL) { while(fileNode != NULL) {
if(!validateNode(&fileNode, true, "folder", "file", NULL)) { if(!validateNode(&fileNode, true, "folder", "file", NULL)) {
+2 -2
View File
@@ -8,12 +8,12 @@
void freeFOMod(FOMod_t * fomod) { void freeFOMod(FOMod_t * fomod) {
for(int i = 0; i < fomod->condFilesCount; i++) { for(int i = 0; i < fomod->condFilesCount; i++) {
FOModCondFile_t * condFile = &(fomod->condFiles[i]); FOModCondFile_t * condFile = &(fomod->condFiles[i]);
for(int fileId = 0; fileId < condFile->fileCount; fileId++) { for(long fileId = 0; fileId < condFile->fileCount; fileId++) {
free(condFile->files[fileId].destination); free(condFile->files[fileId].destination);
free(condFile->files[fileId].source); free(condFile->files[fileId].source);
} }
for(int flagId = 0; flagId < condFile->flagCount; flagId++) { for(long flagId = 0; flagId < condFile->flagCount; flagId++) {
FOModFlag_t * flag = &(condFile->requiredFlags[flagId]); FOModFlag_t * flag = &(condFile->requiredFlags[flagId]);
free(flag->name); free(flag->name);
free(flag->value); free(flag->value);
+2 -1
View File
@@ -1,8 +1,9 @@
#include <libaudit.h> #include <libaudit.h>
#include <pwd.h> #include <pwd.h>
#include <string.h> #include <string.h>
#include "getHome.h"
char * getHome() { char * getHome(void) {
//not getting home from the env enable us to use sudo //not getting home from the env enable us to use sudo
struct passwd *pw = getpwuid(audit_getloginuid()); struct passwd *pw = getpwuid(audit_getloginuid());
return strdup(pw->pw_dir); return strdup(pw->pw_dir);
+1 -1
View File
@@ -5,4 +5,4 @@
* *
* @return char* path to the home dir * @return char* path to the home dir
*/ */
char * getHome(); char * getHome(void);
+1 -1
View File
@@ -97,7 +97,7 @@ static int un7z(char * path, const char * outdir) {
} }
static const char * extractLastPart(const char * filePath, const char delimeter) { static const char * extractLastPart(const char * filePath, const char delimeter) {
const unsigned long length = strlen(filePath); const int length = strlen(filePath);
long index = -1; long index = -1;
for(long i= length - 1; i >= 0; i--) { for(long i= length - 1; i >= 0; i--) {
if(filePath[i] == delimeter) { if(filePath[i] == delimeter) {
+3 -3
View File
@@ -190,7 +190,7 @@ static int installAndUninstallMod(int argc, char ** argv, bool install) {
GList * mods = listFilesInFolder(modFolder); GList * mods = listFilesInFolder(modFolder);
GList * modsFirstPointer = mods; GList * modsFirstPointer = mods;
for(int i = 0; i < modId; i++) { for(unsigned long i = 0; i < modId; i++) {
mods = g_list_next(mods); mods = g_list_next(mods);
} }
@@ -427,7 +427,7 @@ static int removeMod(int argc, char ** argv) {
GList * mods = listFilesInFolder(modFolder); GList * mods = listFilesInFolder(modFolder);
GList * modsFirstPointer = mods; GList * modsFirstPointer = mods;
for(int i = 0; i < modId; i++) { for(unsigned long i = 0; i < modId; i++) {
mods = g_list_next(mods); mods = g_list_next(mods);
} }
@@ -469,7 +469,7 @@ static int fomod(int argc, char ** argv) {
GList * mods = listFilesInFolder(modFolder); GList * mods = listFilesInFolder(modFolder);
GList * modsFirstPointer = mods; GList * modsFirstPointer = mods;
for(int i = 0; i < modId; i++) { for(unsigned long i = 0; i < modId; i++) {
mods = g_list_next(mods); mods = g_list_next(mods);
} }
+13 -5
View File
@@ -12,6 +12,15 @@
enum FieldIds { FIELD_PATH, FIELD_LABEL, FIELD_CONTENT_ID, FIELD_TOTAL_SIZE, FIELD_CLEAN_BYTES, FIELD_CORRUPTION, FIELD_APPS }; enum FieldIds { FIELD_PATH, FIELD_LABEL, FIELD_CONTENT_ID, FIELD_TOTAL_SIZE, FIELD_CLEAN_BYTES, FIELD_CORRUPTION, FIELD_APPS };
// relative to the home directory
static const char * steamLibraries[] = {
"/.steam/root/",
"/.steam/steam/",
"/.local/share/steam",
//flatpack steam.
"/.var/app/com.valvesoftware.Steam/.local/share/Steam"
};
static int getFiledId(const char * field) { static int getFiledId(const char * field) {
//replace with a hash + switch //replace with a hash + switch
if(strcmp(field, "path") == 0) { if(strcmp(field, "path") == 0) {
@@ -38,7 +47,6 @@ static ValveLibraries_t * parseVDF(const char * path, size_t * size, int * statu
FILE * fd = fopen(path, "r"); FILE * fd = fopen(path, "r");
char * line = NULL; char * line = NULL;
size_t len = 0; size_t len = 0;
ssize_t read;
*status = EXIT_SUCCESS; *status = EXIT_SUCCESS;
@@ -185,7 +193,7 @@ GHashTable* search_games(int * status) {
char * home = getHome(); char * home = getHome();
*status = EXIT_SUCCESS; *status = EXIT_SUCCESS;
for(int i = 0; i < LEN(steamLibraries); i++) { for(unsigned long i = 0; i < LEN(steamLibraries); i++) {
char * path = g_build_filename(home, steamLibraries[i], "steamapps/libraryfolders.vdf", NULL); char * path = g_build_filename(home, steamLibraries[i], "steamapps/libraryfolders.vdf", NULL);
if (access(path, F_OK) == 0) { if (access(path, F_OK) == 0) {
int parserStatus; int parserStatus;
@@ -208,8 +216,8 @@ GHashTable* search_games(int * status) {
GHashTable* table = g_hash_table_new_full(g_int_hash, g_int_equal, free, free); GHashTable* table = g_hash_table_new_full(g_int_hash, g_int_equal, free, free);
//fill the table //fill the table
for(int i = 0; i < size; i++) { for(unsigned long i = 0; i < size; i++) {
for(int j = 0; j < libraries[i].appsCount; j++) { for(unsigned long j = 0; j < libraries[i].appsCount; j++) {
int gameId = getGameIdFromAppId(libraries[i].apps[j].appid); int gameId = getGameIdFromAppId(libraries[i].apps[j].appid);
if(gameId >= 0) { if(gameId >= 0) {
int * key = malloc(sizeof(int)); int * key = malloc(sizeof(int));
@@ -225,7 +233,7 @@ GHashTable* search_games(int * status) {
int getGameIdFromAppId(u_int32_t appid) { int getGameIdFromAppId(u_int32_t appid) {
for(int k = 0; k < LEN(GAMES_APPIDS); k++) { for(unsigned long k = 0; k < LEN(GAMES_APPIDS); k++) {
if(appid == GAMES_APPIDS[k]) { if(appid == GAMES_APPIDS[k]) {
return k; return k;
} }
+6 -11
View File
@@ -1,6 +1,8 @@
#ifndef __STEAM_H__ #ifndef __STEAM_H__
#define __STEAM_H__ #define __STEAM_H__
#include "macro.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <sys/types.h> #include <sys/types.h>
@@ -23,30 +25,23 @@ typedef struct ValveLibraries {
size_t appsCount; size_t appsCount;
} ValveLibraries_t; } ValveLibraries_t;
// relative to the home directory
const static char * steamLibraries[] = {
"/.steam/root/",
"/.steam/steam/",
"/.local/share/steam",
//flatpack steam.
"/.var/app/com.valvesoftware.Steam/.local/share/Steam"
};
//todo add the older games //todo add the older games
// order has to be the same as in GAMES_NAMES // order has to be the same as in GAMES_NAMES
const static u_int32_t GAMES_APPIDS[] = { static const u_int32_t GAMES_APPIDS[] = {
489830, 489830,
22330, 22330,
377160 377160
}; };
//the name of the game in the steamapps/common folder //the name of the game in the steamapps/common folder
const static char * GAMES_NAMES[] = { static const char * GAMES_NAMES[] = {
"Skyrim Special Edition", "Skyrim Special Edition",
"Oblivion", "Oblivion",
"Fallout 4" "Fallout 4"
}; };
_Static_assert(LEN(GAMES_APPIDS) == LEN(GAMES_NAMES), "Game APPIDS and Game Names doesn't match");
/** /**
* @brief list all installed games and the paths to the game's files * @brief list all installed games and the paths to the game's files
* *