From 8921ce29627b45d78d1870d550418fc3d13dcdbe Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 30 Apr 2022 05:28:06 -0700 Subject: grow memory for visits as needed --- match.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'match.c') diff --git a/match.c b/match.c index 08c0a3a..6bd1426 100644 --- a/match.c +++ b/match.c @@ -1,13 +1,15 @@ #include "match.h" #include +#include struct leg *leg_init(int points, char *name) { struct leg *l = calloc(1, sizeof(*l)); l->name = name; l->start = l->rem = points; - l->visits = calloc(1000, sizeof(*(l->visits))); // FIXME + l->size_visits = 16; + l->visits = calloc(l->size_visits, sizeof(*(l->visits))); return l; } @@ -23,3 +25,12 @@ void leg_free(struct leg *l) free(l->visits); free(l); } + +void leg_grow_visits(struct leg *l) +{ + + size_t bytes = l->size_visits * sizeof(*(l->visits)); + l->size_visits *= 2; + l->visits = realloc(l->visits, 2 * bytes); + memset((char *)l->visits + bytes, 0, bytes); +} -- cgit v1.2.3-70-g09d2