untested bug fix

This commit is contained in:
Marc
2022-10-03 21:23:10 +02:00
parent e2429fee05
commit aaf3b9527e
6 changed files with 142 additions and 107 deletions
+6 -3
View File
@@ -2,6 +2,7 @@
#include "libxml/tree.h"
#include "xmlUtil.h"
#include <stdlib.h>
#include <string.h>
//Maybe integrate this into the rest of the code instead of freeing after the fact
void freeFOMod(FOMod_t * fomod) {
@@ -21,11 +22,10 @@ void freeFOMod(FOMod_t * fomod) {
free(condFile->requiredFlags);
}
free(fomod->condFiles);
free(fomod->moduleImage);
free(fomod->moduleName);
int size = countUntilNull(fomod->requiredInstallFiles);
int size = countUntilNull(fomod->requiredInstallFiles, sizeof(char **));
for(int i = 0; i < size; i++) {
free(fomod->requiredInstallFiles[i]);
}
@@ -46,6 +46,9 @@ void freeFOMod(FOMod_t * fomod) {
free(step->requiredFlags);
free(step->name);
}
//set every counter to zero and every pointer to null
memset(fomod, 0, sizeof(FOMod_t));
}
int parseVisibleNode(xmlNodePtr node, FOModStep_t * step) {
@@ -285,7 +288,7 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
exit(EXIT_FAILURE);
}
int size = countUntilNull(fomod->requiredInstallFiles) + 2;
int size = countUntilNull(fomod->requiredInstallFiles, sizeof(char **)) + 2;
fomod->requiredInstallFiles = realloc(fomod->requiredInstallFiles, sizeof(char *) * size);
//ensure it is null terminated
fomod->requiredInstallFiles[size - 1] = NULL;
+12
View File
@@ -25,7 +25,19 @@ typedef struct FOMod {
int condFilesCount;
} FOMod_t;
/**
* @brief parse a fomod xml file (found inside the mod folder /fomod/moduleconfig.xml (everything should be lowercase))
*
* @param fomodFile path to the moduleconfig.xml
* @param fomod pointer to a new FOMod_t
* @return error code.
*/
int parseFOMod(const char * fomodFile, FOMod_t* fomod);
/**
* @brief Free content of a fomod file.
* @param fomod
*/
void freeFOMod(FOMod_t * fomod);
#endif
+2 -2
View File
@@ -27,10 +27,10 @@ void fixPath(char * path) {
}
}
int countUntilNull(void * pointers) {
int countUntilNull(void * pointers, size_t typeSize) {
int i = 0;
while(pointers != NULL) {
pointers++;
pointers += typeSize;
i++;
}
return i;
+16 -1
View File
@@ -8,9 +8,24 @@
typedef enum FOModOrder { ASC, DESC, ORD } FOModOrder_t;
bool validateNode(xmlNodePtr * node, bool skipText, const char * names, ...);
/**
* @brief Free memory of and xmlChar and return a strdup version. just to make sure there is nothing remaining in libxml
*/
char * freeAndDup(xmlChar * line);
FOModOrder_t getFOModOrder(const char * order);
/**
* @brief replace / by \
* @param path
*/
void fixPath(char * path);
int countUntilNull(void * pointers);
/**
* @brief Count the number of step before null
*
* @param pointers pointer to the list
* @param typeSize size of each element of the list
* @return size
*/
int countUntilNull(void * pointers, size_t typeSize);
#endif