feat: remove all compiler warnings

This commit is contained in:
NunoSempere 2023-05-02 21:33:42 -04:00
parent beb6b21ea6
commit e7f964c1ad
3 changed files with 19 additions and 14 deletions

View File

@ -20,7 +20,7 @@ SRC=./src/mumble.c
MPC=./src/mpc/mpc.c MPC=./src/mpc/mpc.c
## Dependencies ## Dependencies
DEPS_PC=libedit DEPS_PC=libeditline #libedit: an older version
# ^ libm, which doesn't have files which pkg-config can find, grr. # ^ libm, which doesn't have files which pkg-config can find, grr.
DEBUG= #'-g' DEBUG= #'-g'
@ -41,6 +41,6 @@ format: $(SRC)
$(FORMATTER) $(SRC) $(FORMATTER) $(SRC)
debug: debug:
gcc -I/usr/include/editline ./src/mumble.c ./src/mpc/mpc.c -o mumble -lm -ledit -g gcc -I/usr/include/editline ./src/mumble.c ./src/mpc/mpc.c -o mumble -lm -leditline -g
# valgrind --tool=memcheck --leak-check=yes --show-leak-kinds=all ./mumble valgrind --tool=memcheck --leak-check=yes --show-leak-kinds=all ./mumble
valgrind --tool=memcheck --leak-check=yes ./mumble # valgrind --tool=memcheck --leak-check=yes ./mumble

BIN
mumble

Binary file not shown.

View File

@ -1,5 +1,6 @@
#include <editline/history.h> // #include <editline/history.h>
#include <editline/readline.h> // #include <editline/readline.h>
#include <editline.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -16,7 +17,7 @@ int VERBOSE = 2;
printf("\n@ %s (%d): ", __FILE__, __LINE__); \ printf("\n@ %s (%d): ", __FILE__, __LINE__); \
printf(__VA_ARGS__); \ printf(__VA_ARGS__); \
} else { \ } else { \
printf("\n"); \ printf("%s", "\n"); \
printf(__VA_ARGS__); \ printf(__VA_ARGS__); \
} \ } \
} while (0) } while (0)
@ -807,7 +808,7 @@ lispval* evaluate_lispval(lispval* l, lispenv* env)
printfln("Evaluating lispval"); printfln("Evaluating lispval");
// Check if this is neither an s-expression nor a symbol; otherwise return as is. // Check if this is neither an s-expression nor a symbol; otherwise return as is.
if (VERBOSE) if (VERBOSE)
printfln(""); printfln("%s", "");
if (l->type != LISPVAL_SEXPR && l->type != LISPVAL_SYM) if (l->type != LISPVAL_SEXPR && l->type != LISPVAL_SYM)
return l; return l;
@ -825,18 +826,18 @@ lispval* evaluate_lispval(lispval* l, lispenv* env)
// Evaluate the children if needed // Evaluate the children if needed
if (VERBOSE) if (VERBOSE)
printfln("Evaluating children"); printfln("%s", "Evaluating children");
for (int i = 0; i < l->count; i++) { for (int i = 0; i < l->count; i++) {
if (l->cell[i]->type == LISPVAL_SEXPR || l->cell[i]->type == LISPVAL_SYM) { if (l->cell[i]->type == LISPVAL_SEXPR || l->cell[i]->type == LISPVAL_SYM) {
// l->cell[i] = // l->cell[i] =
if (VERBOSE) if (VERBOSE)
printfln(""); printfln("%s", "");
lispval* new = evaluate_lispval(l->cell[i], env); lispval* new = evaluate_lispval(l->cell[i], env);
// delete_lispval(l->cell[i]); // delete_lispval(l->cell[i]);
// ^ gave me a "double free" error. // ^ gave me a "double free" error.
l->cell[i] = new; l->cell[i] = new;
if (VERBOSE) if (VERBOSE)
printfln(""); printfln("%s", "");
} }
} }
// Check if any are errors. // Check if any are errors.
@ -918,8 +919,8 @@ void modify_verbosity(char* command)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
// Info // Info
puts("Mumble version 0.0.2\n"); printfln("%s", "Mumble version 0.0.2\n");
puts("Press Ctrl+C to exit\n"); printfln("%s", "Press Ctrl+C to exit\n");
/* Create Some Parsers */ /* Create Some Parsers */
mpc_parser_t* Number = mpc_new("number"); mpc_parser_t* Number = mpc_new("number");
@ -967,6 +968,7 @@ int main(int argc, char** argv)
if (input == NULL) { if (input == NULL) {
// ^ catches Ctrl+D // ^ catches Ctrl+D
loop = 0; loop = 0;
} else { } else {
/* Attempt to Parse the user Input */ /* Attempt to Parse the user Input */
mpc_result_t result; mpc_result_t result;
@ -1022,11 +1024,14 @@ int main(int argc, char** argv)
add_history(input); add_history(input);
// can't add if input is NULL // can't add if input is NULL
} }
puts(""); printf("%s", "");
free(input); free(input);
input = NULL; input = NULL;
} }
// Clear the history
rl_uninitialize();
// rl_free_line_state();
// Clean up environment // Clean up environment
destroy_lispenv(env); destroy_lispenv(env);