Advent of Code

Check-in [16cb8577e3]
Login

Check-in [16cb8577e3]

Overview
Comment:add space for terminating zero
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 16cb8577e3507ea9c7b7332ec4aaea8bbcebea104fb2e7cfcf776f98ccb72e15
User & Date: nnz on 2024-12-06 13:54:13
Other Links: manifest | tags
Context
2024-12-06
16:28
202406 2nd star (not pretty) check-in: 6538876b94 user: nnz tags: trunk
13:54
add space for terminating zero check-in: 16cb8577e3 user: nnz tags: trunk
13:49
ready for brute force check-in: aca10ca251 user: nnz tags: trunk
Changes

Modified aocutils.c from [ff66d0a337] to [68c37aa5e0].

40
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68







-
+













+







    }

    int ch;
    char *tmp = malloc(512);
    size_t s = 512;
    size_t r = 0;
    while ((ch = fgetc(h)) != EOF) {
        if (r == s) {
        if (r+1 == s) {
            // grow the array (by golden ratio)
            char *ttmp = realloc(tmp, (13*s) / 8);
            if (ttmp) {
                tmp = ttmp;
                s = (13*s) / 8;
            } else {
                free(tmp);
                return 0;
            }
        }
        tmp[r++] = ch;
    }
    fclose(h);
    tmp[r] = 0;
    *dst = tmp;

    return r;
}

unsigned distance(unsigned a, unsigned b) {
    if (a > b) return a - b;