Skip to content

Commit 9deb0ca

Browse files
committed
Fix crash on file not found
1 parent 04a3183 commit 9deb0ca

File tree

4 files changed

+4
-82
lines changed

4 files changed

+4
-82
lines changed

examples/test

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/minilisp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ static size_t read_file(char *fname, char **text) {
946946
size_t length = 0;
947947
FILE *f = fopen(fname, "r");
948948
if (!f) {
949-
error("Failed to load file %s", filepos.line_num, fname);
949+
printf("Failed to load file %s\n", fname);
950950
return 0;
951951
}
952952

@@ -957,14 +957,14 @@ static size_t read_file(char *fname, char **text) {
957957

958958
*text = malloc(length + 1);
959959
if (!*text) {
960-
error("Out of memory.", filepos.line_num);
960+
puts("Out of memory.");
961961
fclose(f);
962962
return 0;
963963
}
964964

965965
size_t read = fread(*text, 1, length, f);
966966
if (read != length) {
967-
error("Failed to read entire file", filepos.line_num);
967+
printf("Failed to read entire file %s\n", fname);
968968
free(*text);
969969
*text = NULL;
970970
fclose(f);

src/repl.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ char *hints(const char *buf, const char **ansi1, const char **ansi2) {
4949
return NULL;
5050
}
5151

52-
extern void reset_minilisp(Obj **env);
53-
5452
// This struct keeps track of the current file/line being evaluated
5553
filepos_t filepos = {"", 0, 1};
5654

@@ -85,8 +83,6 @@ void minilisp(char *text, size_t length, bool with_repl, Obj **env, Obj **expr)
8583
FILE * stream = fmemopen(line, strlen(line), "r");
8684
// Redirect stdin to the in memory stream in order to use getchar()
8785
stdin = stream;
88-
89-
//usleep(10000);
9086

9187
if (line[0] != '\0' && line[0] != '/') {
9288
eval_input(line, env, expr);

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -x
1+
#!/bin/bash
22

33
function fail() {
44
echo -n -e '\e[1;31m[ERROR]\e[0m '

0 commit comments

Comments
 (0)