diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c8a6b8..15ff245 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10) project(simworld VERSION 0.0.1 LANGUAGES C) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat=2 -Wshadow -Wwrite-strings -Wstrict-prototypes -g") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c17 -Wpedantic -pedantic-errors -Wformat=2 -Wshadow -Wwrite-strings -Wstrict-prototypes -g") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/client/src/sock.c b/client/src/sock.c index a726a82..9362017 100644 --- a/client/src/sock.c +++ b/client/src/sock.c @@ -1,6 +1,7 @@ // sock.c #include +#include #include #include #include diff --git a/common/src/entity/registry.c b/common/src/entity/registry.c index 8929638..9f3733e 100644 --- a/common/src/entity/registry.c +++ b/common/src/entity/registry.c @@ -17,10 +17,12 @@ enum error_t entity_registrant_init( if (name == NULL || strlen(name) > MAX_NAME_LENGTH) return ERR_INPUT; - char const *dup = strndup(name, MAX_NAME_LENGTH); - if (dup == NULL) return ERR_ALLOC; + char *namecpy = calloc(MAX_NAME_LENGTH, sizeof(char)); + if (namecpy == NULL) return ERR_ALLOC; - self->name = dup; + strncpy(namecpy, name, MAX_NAME_LENGTH); + + self->name = namecpy; self->tile = tile; return ERR_OK; @@ -67,9 +69,9 @@ enum error_t entity_registry_append( assert(self != NULL && registrant != NULL); self->size += 1; - self->entities = reallocarray( - self->entities, self->size, - sizeof(struct entity_registrant_t) + self->entities = realloc( + self->entities, + self->size * sizeof(struct entity_registrant_t) ); if (self->entities == NULL) return ERR_ALLOC; diff --git a/server/src/main.c b/server/src/main.c index 39dbaa8..57f7bb3 100644 --- a/server/src/main.c +++ b/server/src/main.c @@ -14,7 +14,9 @@ #include "sock.h" #include "data.h" -static void handle_signal(int _) { +static void handle_signal(int signal_no) { + (void)signal_no; + remove(SOCK_PATH); exit(0); } @@ -60,7 +62,7 @@ int main(int argc, char **argv) { if (err) goto handle_error_world; // Temporary code because I just realised I need to properly serialise - // data because don't work cross-socket + // data because pointers don't work cross-socket // TODO: Serialise to JSON const char *fmt = "%zu (%s) (%zu, %zu) '%c'\n"; struct entity_t const *const entity = &data.world.entities[0]; diff --git a/server/src/sock.c b/server/src/sock.c index 30f3cc7..60049d9 100644 --- a/server/src/sock.c +++ b/server/src/sock.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include diff --git a/server/src/sock.h b/server/src/sock.h index b5b4a46..6509dcf 100644 --- a/server/src/sock.h +++ b/server/src/sock.h @@ -11,7 +11,7 @@ enum error_t sock_init(int *); void sock_free(int const *); -typedef enum error_t (* gameloop_fn)(struct data_t *);; +typedef enum error_t (* gameloop_fn)(struct data_t *); enum error_t sock_loop(struct data_t *, gameloop_fn); #endif