commit 7ef5ddd38b62e5e0f587e8632281994345b43ff1
parent 8cd6edcd11d419092f195011c0640d01e06647e8
Author: bsandro <brian.drosan@gmail.com>
Date: Mon, 13 Dec 2021 03:09:42 +0200
strncpy boundaries checked
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/day12/puzzle.c b/day12/puzzle.c
@@ -187,7 +187,7 @@ void add_path(struct array_t *nodes, const char *str) {
if (*token != '\0') {
assert(i < 2);
assert(strlen(token) < NAME_LEN);
- strncpy(names[i], token, NAME_LEN);
+ strncpy(names[i], token, NAME_LEN-1);
++i;
}
}
@@ -226,7 +226,7 @@ int node_add(struct array_t *nodes, const char *name) {
struct node_t *data = (struct node_t *)nodes->data;
struct node_t *node = &data[nodes->count++];
node->id = last_id++;
- strncpy(node->name, name, NAME_LEN);
+ strncpy(node->name, name, NAME_LEN-1);
if (strncmp(node->name, NAME_START, NAME_LEN) == 0) {
node->is_start = true;
} else if (strncmp(node->name, NAME_END, NAME_LEN) == 0) {