Change certain asserts in configfile to logs

This commit is contained in:
MysterD 2023-04-01 03:39:23 -07:00
parent 74b773d5fd
commit d09d66b5d5
1 changed files with 11 additions and 3 deletions

View File

@ -17,6 +17,7 @@
#include "pc/network/ban_list.h" #include "pc/network/ban_list.h"
#include "pc/crash_handler.h" #include "pc/crash_handler.h"
#include "pc/network/moderator_list.h" #include "pc/network/moderator_list.h"
#include "debuglog.h"
#define ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0])) #define ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0]))
@ -362,6 +363,7 @@ static char *read_file_line(fs_file_t *file) {
size_t offset = 0; // offset in buffer to write size_t offset = 0; // offset in buffer to write
buffer = malloc(bufferSize); buffer = malloc(bufferSize);
buffer[0] = '\0';
while (1) { while (1) {
// Read a line from the file // Read a line from the file
if (fs_readline(file, buffer + offset, bufferSize - offset) == NULL) { if (fs_readline(file, buffer + offset, bufferSize - offset) == NULL) {
@ -369,7 +371,11 @@ static char *read_file_line(fs_file_t *file) {
return NULL; // Nothing could be read. return NULL; // Nothing could be read.
} }
offset = strlen(buffer); offset = strlen(buffer);
assert(offset > 0); if (offset <= 0) {
LOG_ERROR("Configfile offset <= 0");
return NULL;
}
// If a newline was found, remove the trailing newline and exit // If a newline was found, remove the trailing newline and exit
if (buffer[offset - 1] == '\n') { if (buffer[offset - 1] == '\n') {
@ -521,7 +527,8 @@ void configfile_load(const char *filename) {
} }
break; break;
default: default:
assert(0); // bad type LOG_ERROR("Configfile read bad type '%d': %s", (int)option->type, line);
goto NEXT_OPTION;
} }
printf("option: '%s', value:", tokens[0]); printf("option: '%s', value:", tokens[0]);
for (int i = 1; i < numTokens; ++i) printf(" '%s'", tokens[i]); for (int i = 1; i < numTokens; ++i) printf(" '%s'", tokens[i]);
@ -585,7 +592,8 @@ void configfile_save(const char *filename) {
fprintf(file, "%s %02x %02x %02x\n", option->name, (*option->colorValue)[0], (*option->colorValue)[1], (*option->colorValue)[2]); fprintf(file, "%s %02x %02x %02x\n", option->name, (*option->colorValue)[0], (*option->colorValue)[1], (*option->colorValue)[2]);
break; break;
default: default:
assert(0); // unknown type LOG_ERROR("Configfile wrote bad type '%d': %s", (int)option->type, option->name);
break;
} }
} }