Skip to content

Commit 9ec9c7c

Browse files
rename dirs to include name of respective programming language + run ubsan and asan on all c and c++ solutions
1 parent af9de18 commit 9ec9c7c

File tree

660 files changed

+500
-27306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

660 files changed

+500
-27306
lines changed

Diff for: .clang-format

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
Standard: c++20
21
TabWidth: 2
32
UseTab: Never

Diff for: 2015-c/.clangd

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CompileFlags:
2+
Add: [-std=c99, -Wall, -Wextra, -Wpedantic ]

Diff for: 2015/.gitignore renamed to 2015-c/.gitignore

File renamed without changes.
File renamed without changes.

Diff for: 2015/01-not-quite-lisp/main.c renamed to 2015-c/01-not-quite-lisp/main.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include "../adventofcode.h"
22
#include <stdio.h>
33
#include <stdlib.h>
4-
#include <time.h>
54

6-
int main() {
5+
int main(void) {
76
clock_t start_t = clock_time();
87
char input[64 * 1024] = "";
98
int ninput = (int)read_input_file(input, 64 * 1024, "input.txt");

Diff for: 2015/02-i-was-told-there-would-be-no-math/main.c renamed to 2015-c/02-i-was-told-there-would-be-no-math/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int compare_ints(const void *a, const void *b) {
2525
return 0;
2626
}
2727

28-
int main() {
28+
int main(void) {
2929
clock_t start_t, end_t;
3030
start_t = clock();
3131

Diff for: 2015/03-perfectly-spherical-houses-in-a-vacuum/main.c renamed to 2015-c/03-perfectly-spherical-houses-in-a-vacuum/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int solve(const char *s, uint8_t nworkers) {
7979
return count;
8080
}
8181

82-
int main() {
82+
int main(void) {
8383
clock_t start_t, end_t;
8484
start_t = clock();
8585

File renamed without changes.

Diff for: 2015/04-md5/main.c renamed to 2015-c/04-md5/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ char *itoa(int value, char *result, int base) {
3939
return result;
4040
}
4141

42-
int main() {
42+
int main(void) {
4343
clock_t start_t = clock_time();
4444
char input[64 * 1024] = "";
4545
size_t keylen = read_input_file(input, 64 * 1024, "input.txt");
File renamed without changes.

Diff for: 2015/05-nice-strings/main.c renamed to 2015-c/05-nice-strings/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int str_is_nice_v2(char *s) {
6161
return r1 == 1 && r2 == 1;
6262
}
6363

64-
int main() {
64+
int main(void) {
6565
clock_t start_t, end_t;
6666
start_t = clock();
6767

Diff for: 2015/06-probably-a-fire-hazard/main.c renamed to 2015-c/06-probably-a-fire-hazard/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static inline char *parse_int(uint16_t *dst, char *s) {
1515
return s;
1616
}
1717

18-
int main() {
18+
int main(void) {
1919
clock_t start_t, end_t;
2020
start_t = clock();
2121

Diff for: 2015/07-some-assembly-required/main.c renamed to 2015-c/07-some-assembly-required/main.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct instruction {
5858
int rhs_value;
5959
} instruction_t;
6060

61-
void print_instruction(instruction_t i) {
61+
void print_instruction(const instruction_t i) {
6262
switch (i.opcode) {
6363
case DIRECT:
6464
printf("%s = %s%d\n", i.target, i.lhs_ident, i.lhs_value);
@@ -145,11 +145,9 @@ int run(instruction_t *instructions, int ninstructions) {
145145
}
146146
}
147147
}
148-
149-
abort();
150148
}
151149

152-
int main() {
150+
int main(void) {
153151
char input[32 * 1024] = "";
154152
read_input_file(input, 32 * 1024, "input.txt");
155153
clock_t start_t = clock_time();
File renamed without changes.

Diff for: 2015/08-matchsticks/main.c renamed to 2015-c/08-matchsticks/main.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "../adventofcode.h"
22
#include <stdio.h>
3-
#include <time.h>
43

5-
int main() {
4+
int main(void) {
65
clock_t start_t = clock_time();
76
char input[32 * 1024];
87
read_input_file(input, 32 * 1024, "input.txt");

Diff for: 2015/09-all-in-a-single-night/main.c renamed to 2015-c/09-all-in-a-single-night/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int getcity(char cities[16][16], int ncities, char *c) {
8484
return -1;
8585
}
8686

87-
int main() {
87+
int main(void) {
8888
clock_t tstart = clock_time();
8989
char input[1024 * 64] = "";
9090
read_input_file(input, 1024 * 64, "input.txt");
File renamed without changes.

Diff for: 2015/10-elves-look-elves-say/main.c renamed to 2015-c/10-elves-look-elves-say/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int apply(char *dst, char *in) {
2222
return (int)(o - dst);
2323
}
2424

25-
int main() {
25+
int main(void) {
2626
clock_t start_t = clock_time();
2727

2828
// single malloc call for 16MB of memory
File renamed without changes.

Diff for: 2015/11-corporate-policy/main.c renamed to 2015-c/11-corporate-policy/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void pw_increment(char *src) {
5353
} while (pw_is_valid(src) == 0);
5454
}
5555

56-
int main() {
56+
int main(void) {
5757
clock_t start_t = clock_time();
5858

5959
assert(pw_is_valid("hijklmmn") == 0);
File renamed without changes.

Diff for: 2015/12-jsabacusframework-io/main.c renamed to 2015-c/12-jsabacusframework-io/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int pt2(const char *input) {
7575
return objsums[0];
7676
}
7777

78-
int main() {
78+
int main(void) {
7979
clock_t tstart = clock_time();
8080
char input[32 * 1024] = "";
8181
read_input_file(input, 1024 * 32, "input.txt");

Diff for: 2015/13-knights-of-the-dinner-table/main.c renamed to 2015-c/13-knights-of-the-dinner-table/main.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ int permute(int matrix[32][32], int buf[], int from, int to, int score) {
8585
return score;
8686
}
8787

88-
int main() {
88+
int main(void) {
8989
clock_t tstart = clock_time();
9090
char input[1024 * 64] = "";
9191
read_input_file(input, 1024 * 64, "input.txt");
92-
int a1 = 0, a2 = 0;
93-
92+
int a1 = 0;
93+
int a2 = 0;
9494
int matrix[32][32];
9595
char seats[32][32];
9696
int nseats = parse(input, matrix, seats);
9797

9898
// create buf with combinations
99-
int buf[nseats];
99+
int buf[nseats + 1];
100100
for (int i = 0; i < nseats; i++) {
101101
buf[i] = i;
102102
}
File renamed without changes.

Diff for: 2015/14-reindeer-olympics/main.c renamed to 2015-c/14-reindeer-olympics/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void parse(reindeer_t *players, int *nplayers) {
126126
*nplayers = n;
127127
}
128128

129-
int main() {
129+
int main(void) {
130130
clock_t start_t = clock_time();
131131
reindeer_t players[10];
132132
int nplayers = 0;

Diff for: 2015/15-science-for-hungry-people/main.c renamed to 2015-c/15-science-for-hungry-people/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void parse(struct ingredient *ingredients, int *ningredients) {
4545
*ningredients = n;
4646
}
4747

48-
int main() {
48+
int main(void) {
4949
clock_t start_t = clock_time();
5050

5151
struct ingredient ingredients[4];
File renamed without changes.

Diff for: 2015/16-aunt-sue/main.c renamed to 2015-c/16-aunt-sue/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int pt2(char *input) {
103103
return -1;
104104
}
105105

106-
int main() {
106+
int main(void) {
107107
clock_t start_t = clock_time();
108108
char input[64 * 1024];
109109
read_input_file(input, 64 * 1024, "input.txt");

Diff for: 2015/17-no-such-thing-as-too-much/main.c renamed to 2015-c/17-no-such-thing-as-too-much/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int parse(const char *s, int *dest) {
6262
return n;
6363
}
6464

65-
int main() {
65+
int main(void) {
6666
clock_t start_t = clock_time();
6767

6868
char input[1024];

Diff for: 2015/18-like-a-gif-for-your-yard/main.c renamed to 2015-c/18-like-a-gif-for-your-yard/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int solve(char *g, int size, int broken) {
7878
return count_on(grid, size);
7979
}
8080

81-
int main() {
81+
int main(void) {
8282
clock_t start_t = clock_time();
8383
char input[1024 * 32] = "";
8484
read_input_file(input, 32 * 1024, "input.txt");
File renamed without changes.

Diff for: 2015/19-medicine-for-rudolph/main.c renamed to 2015-c/19-medicine-for-rudolph/main.c

+4-14
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,15 @@ int parse(const char *s, char needles[][16], char replacements[][16],
2828
return n;
2929
}
3030

31-
// indexof returns the index of the given string in the array, or -1
32-
static inline int indexof(char *haystack[], int n, char *needle) {
33-
for (int j = 0; j < n; j++) {
34-
if (strcmp(haystack[j], needle) == 0) {
35-
return j;
36-
}
37-
}
38-
39-
return -1;
40-
}
41-
42-
int pt1(char needles[][16], char replacements[][16], int n, char *medicine) {
31+
int pt1(const char needles[][16], char replacements[][16], int n,
32+
char *medicine) {
4333
hashmap_t hm = hashmap_new(1024);
4434
int nmolecules = 0;
4535
char buf[1024];
4636
size_t len = strlen(medicine);
4737
for (size_t pos = 0; pos < len; pos++) {
4838
for (int i = 0; i < n; i++) {
49-
char *needle = needles[i];
39+
const char *needle = needles[i];
5040

5141
// check if current position matches needle
5242
size_t needle_length = strlen(needle);
@@ -108,7 +98,7 @@ int pt2(char needles[][16], char replacements[][16], int n, char *medicine) {
10898
return steps;
10999
}
110100

111-
int main() {
101+
int main(void) {
112102
clock_t start_t = clock_time();
113103

114104
char input[1024 * 32] = "";
File renamed without changes.

Diff for: 2015/20-infinite-elves-and-infinite-houses/main.c renamed to 2015-c/20-infinite-elves-and-infinite-houses/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int pt1(int *houses, int nhouses, int target, int elfvalue, int elflimit) {
3131
return -1;
3232
}
3333

34-
int main() {
34+
int main(void) {
3535
clock_t start_t = clock_time();
3636

3737
char input[64];
File renamed without changes.

Diff for: 2015/21-rpg-simulator-20xx/main.c renamed to 2015-c/21-rpg-simulator-20xx/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct answer permute(struct stats player, struct stats boss) {
9595
return (struct answer){cheap_win, expensive_lose};
9696
}
9797

98-
int main() {
98+
int main(void) {
9999
clock_t start_t = clock_time();
100100
char input[1024];
101101
read_input_file(input, 1024, "input.txt");

Diff for: 2015/22-wizard-simulator-20xx/main.c renamed to 2015-c/22-wizard-simulator-20xx/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct answer {
144144
// return (struct answer){cheap_win, expensive_lose};
145145
// }
146146

147-
int main() {
147+
int main(void) {
148148
clock_t start_t = clock_time();
149149
char input[1024];
150150
read_input_file(input, 1024, "input_test.txt");

Diff for: 2015/23-opening-the-turing-lock/main.c renamed to 2015-c/23-opening-the-turing-lock/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int parse(char *filename, int codes[64][3]) {
102102
return ncodes;
103103
}
104104

105-
int main() {
105+
int main(void) {
106106
clock_t start_t = clock_time();
107107

108108
int codes[64][3];

Diff for: 2015/24-it-hangs-in-the-balance/main.c renamed to 2015-c/24-it-hangs-in-the-balance/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static unsigned long sumto(const int weights[], const unsigned int nweights,
5757
return best;
5858
}
5959

60-
int main() {
60+
int main(void) {
6161
clock_t start_t = clock_time();
6262

6363
char input[1024];
File renamed without changes.
File renamed without changes.

Diff for: 2015/25-let-it-snow/main.c renamed to 2015-c/25-let-it-snow/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ unsigned long value_at(int row, int col) {
2929
return v;
3030
}
3131

32-
int main() {
32+
int main(void) {
3333
clock_t start_t = clock_time();
3434

3535
char input[1024];

Diff for: 2015/README.md renamed to 2015-c/README.md

Diff for: 2015/adventofcode.h renamed to 2015-c/adventofcode.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ static inline const char *skip_until_digit(const char *s) {
118118
return s;
119119
}
120120

121-
static clock_t clock_time() { return clock(); }
121+
static clock_t clock_time(void) { return clock(); }
122122

123123
static double clock_time_since(clock_t start_t) {
124124
clock_t end_t = clock();
125125
return (double)(end_t - start_t) / CLOCKS_PER_SEC * 1000;
126-
}
126+
}

Diff for: 2015/hashmap.h renamed to 2015-c/hashmap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ int *hashmap_get(hashmap_t *h, unsigned char *data, size_t datasize) {
108108
return &h->entries[k].value;
109109
}
110110

111-
void hashmap_free(hashmap_t *h) { free(h->entries); }
111+
void hashmap_free(hashmap_t *h) { free(h->entries); }

Diff for: 2015/memcheck-all.sh renamed to 2015-c/memcheck-all.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
for d in */; do
66
cd "$d"
7-
cc -O2 -Wall -Werror -Wpedantic -g main.c -lcrypto
7+
cc -O2 -Wall -Werror -Wpedantic -g -fsanitize=undefined main.c -lcrypto
88
valgrind -s --track-origins=yes --leak-check=full ./a.out
99
echo ""
1010
read -n 1 -p "Next? [Any key to proceed]"

Diff for: 2015/run.sh renamed to 2015-c/run.sh

File renamed without changes.

Diff for: 2015/01-not-quite-lisp/input.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)