X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=05a.c;h=8a2e9f1a40b49f0aa9c55fd7aefe963425149d08;hb=a622aa41088ddf29d38c50e2032ca84984b0e12b;hp=cdebe3838e38401e36f1996044399976dc9f6873;hpb=464433396dbb86c54b50aefa08b4ec188d82c609;p=advent21.git diff --git a/05a.c b/05a.c index cdebe38..8a2e9f1 100644 --- a/05a.c +++ b/05a.c @@ -1,4 +1,5 @@ #include +#include #include #define SWAP(x, y) { x ^= y; y ^= x; x ^= y; } @@ -9,13 +10,16 @@ struct entry { struct point key; int i; UT_hash_handle hh; }; void mark_point(int x, int y, struct entry **entries, int *r) { struct entry *p; - struct point s = { .x=x, .y=y }; + struct point s; + memset(&s, 0, sizeof s); + s.x = x; + s.y = y; HASH_FIND(hh, *entries, &s, sizeof(struct point), p); if (p) { if (p->i++ == 1) *r = *r+1; } else { - p = malloc(sizeof(struct entry)); + p = calloc(1, sizeof(struct entry)); p->key = s; p->i = 1; HASH_ADD(hh, *entries, key, sizeof(struct point), p);