fix compiler warnings
This commit is contained in:
parent
251a7f405e
commit
3e65bd58c5
15
Makefile
Normal file
15
Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
CMAKE_OPTS=-DCMAKE_EXPORT_COMPILE_COMMANDS=1
|
||||
|
||||
.PHONY: all clean run
|
||||
|
||||
all:
|
||||
mkdir -p build
|
||||
cd build && \
|
||||
cmake ${CMAKE_OPTS} .. && \
|
||||
$(MAKE) && \
|
||||
cp compile_commands.json ..
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
rm -f compile_commands.json
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
char *md5_str(const char *);
|
||||
|
||||
char *capture_system(const char *);
|
||||
|
||||
Vector *string_to_int_vector(const char *input_string, const char *delim);
|
||||
|
||||
#endif
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 34b21c494b6b9fcc9e3c9e7d98bfea6114eefa41
|
||||
Subproject commit 4b59b4789cd743dc874399784a1918e9f11086d1
|
@ -30,8 +30,9 @@ void advent2015day04(void) {
|
||||
int c = 0, five = 0, six = 0;
|
||||
|
||||
while (!five || !six) {
|
||||
char test[strlen(input) + 8];
|
||||
sprintf(test, "%s%d", input, c);
|
||||
int sz = strlen(input) + 8;
|
||||
char test[sz];
|
||||
snprintf(test, sz, "%s%d", input, c);
|
||||
char *md5 = md5_str(test);
|
||||
|
||||
if (!five && is_five(md5)) {
|
||||
|
@ -91,7 +91,7 @@ void advent2015day06(void) {
|
||||
s1503 ins[sz];
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
char *s = malloc(sizeof(char) * 64);
|
||||
strcpy(s, input[i]);
|
||||
strncpy(s, input[i], 64);
|
||||
size_t sp_sz = 0;
|
||||
char **sp = split(s, &sp_sz, " ");
|
||||
|
||||
|
@ -26,7 +26,7 @@ static void set_wire(const char *name, int v) {
|
||||
HASH_FIND_STR(wires, name, w);
|
||||
if (w == NULL) {
|
||||
w = malloc(sizeof(struct Wire));
|
||||
strcpy(w->name, name);
|
||||
strlcpy(w->name, name, 8);
|
||||
HASH_ADD_STR(wires, name, w);
|
||||
}
|
||||
w->val = v;
|
||||
@ -68,11 +68,11 @@ void advent2015day07(void) {
|
||||
int a_set = LFFALSE;
|
||||
|
||||
while (!a_set) {
|
||||
char *buf = malloc(sizeof(char) * strlen(input[i]) + 1);
|
||||
strcpy(buf, input[i]);
|
||||
int sz = strlen(input[i]) + 1;
|
||||
char *buf = malloc(sizeof(char) * sz);
|
||||
strlcpy(buf, input[i], sz);
|
||||
size_t sp_sz = 0;
|
||||
char **sp = split(buf, &sp_sz, " ");
|
||||
int s = 0;
|
||||
|
||||
if (sp_sz == 3) {
|
||||
uint16_t a = get_val(sp[0]);
|
||||
@ -114,4 +114,5 @@ void advent2015day07(void) {
|
||||
|
||||
printf("%u\n", get_wire("a")->val);
|
||||
del_lines(input);
|
||||
clear_wires();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ static void parse(char *input, struct Game *g) {
|
||||
sscanf(input, "Game %d:", &g->id);
|
||||
const char *c = strchr(input, ':') + 1;
|
||||
char cpy[1024];
|
||||
strcpy(cpy, c);
|
||||
strncpy(cpy, c, 1024);
|
||||
|
||||
char *token = strtok(cpy, ",;");
|
||||
while (token != NULL) {
|
||||
|
@ -29,22 +29,11 @@ char *md5_str(const char *input) {
|
||||
|
||||
char *md5string = malloc(33);
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
sprintf(&md5string[i * 2], "%02x", (unsigned int) digest[i]);
|
||||
snprintf(&md5string[i * 2], 33, "%02x", (unsigned int) digest[i]);
|
||||
}
|
||||
return md5string;
|
||||
}
|
||||
|
||||
char *capture_system(const char *cmd) {
|
||||
char *buf = malloc(256);
|
||||
FILE *tmp = popen(cmd, "r");
|
||||
if (tmp == NULL) {
|
||||
printf("failed to open FILE *tmp\n");
|
||||
exit(1);
|
||||
}
|
||||
fgets(buf, 256, tmp);
|
||||
return buf;
|
||||
}
|
||||
|
||||
Vector *string_to_int_vector(const char *input_string, const char* delim) {
|
||||
char *copy = strdup(input_string);
|
||||
char* token = strtok(copy, delim);
|
||||
@ -54,7 +43,7 @@ Vector *string_to_int_vector(const char *input_string, const char* delim) {
|
||||
while (token != NULL) {
|
||||
int *i = malloc(sizeof(int));
|
||||
*i = atoi(token);
|
||||
vec_push(v, i);
|
||||
vec_push(v, i, NULL);
|
||||
token = strtok(NULL, delim);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user