X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fcommand_db.c;h=61ae4b11ba718777de7af6292249b687cd8c6cd3;hb=0e6c855b67e0cd3def7196396f3d1f45ff85b692;hp=d5af5c27f8bdf8f6944f384f790e931168bc3d45;hpb=2f0b15e05b0df7e10a2d0bb04ce4648455d980a8;p=plomrogue diff --git a/src/command_db.c b/src/command_db.c index d5af5c2..61ae4b1 100644 --- a/src/command_db.c +++ b/src/command_db.c @@ -7,7 +7,7 @@ #include /* for strlen(), strtok() */ #include "main.h" /* for World struct */ #include "rexit.h" /* for exit_err() */ -#include "misc.h" /* for textfile_sizes() */ +#include "readwrite.h" /* for textfile_sizes() */ @@ -87,12 +87,12 @@ extern void init_command_db(struct World * world) exit_err(NULL == file, world, err_o); uint16_t lines, linemax; exit_err(textfile_sizes(file, &linemax, &lines), world, err_s); + char line[linemax + 1]; - char line[linemax]; struct Command * cmds = malloc(lines * sizeof(struct Command)); exit_err(NULL == line, world, err_m); uint8_t i = 0; - while (fgets(line, linemax, file)) + while (fgets(line, linemax + 1, file)) { cmds[i].id = atoi(strtok(line, " ")); copy_tokenized_string(world, &cmds[i].dsc_short, " ", err_m);