summaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-30 05:28:06 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-30 05:28:06 -0700
commit8921ce29627b45d78d1870d550418fc3d13dcdbe (patch)
tree1b5b37a317c93d55247ac3da719a8dcd8eaf072b /match.c
parentfbdb393ae1e2ea5d368e4dda1577a10715e26a75 (diff)
downloaddartboat-8921ce29627b45d78d1870d550418fc3d13dcdbe.tar.gz
dartboat-8921ce29627b45d78d1870d550418fc3d13dcdbe.tar.xz
grow memory for visits as needed
Diffstat (limited to 'match.c')
-rw-r--r--match.c13
1 files changed, 12 insertions, 1 deletions
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 <stdlib.h>
+#include <string.h>
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);
+}