From 6bbc77a69cba4b17af0f4f8a6652f8e90beecdba Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 6 Oct 2024 12:19:06 +0200 Subject: [PATCH] Segfault with passing a program with `-` using stdin. Using no module with `-` would reject the program. #1523 --- releasenotes.md | 2 ++ src/compiler/context.c | 6 ++++++ src/compiler/parser.c | 1 + 3 files changed, 9 insertions(+) diff --git a/releasenotes.md b/releasenotes.md index f679ed46e..124c21281 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -12,6 +12,8 @@ - `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489. - Unexpected compile error using a typed constant with `copysign` #1517 - Incorrect subscript resolution #1519. +- Segfault with passing a program with `-` using stdin. +- Using no module with `-` would reject the program. ### Stdlib changes - Remove unintended print of `char[]` as String diff --git a/src/compiler/context.c b/src/compiler/context.c index 22e289da1..b427d55f9 100644 --- a/src/compiler/context.c +++ b/src/compiler/context.c @@ -46,6 +46,12 @@ static inline bool create_module_or_check_name(CompilationUnit *unit, Path *modu static bool filename_to_module_in_buffer(const char *path) { + if (str_eq("", path)) + { + scratch_buffer_clear(); + scratch_buffer_append("stdin_file"); + return true; + } int len = (int)strlen(path); int last_slash = 0; int last_dot = -1; diff --git a/src/compiler/parser.c b/src/compiler/parser.c index 635c8c693..79e73d83d 100644 --- a/src/compiler/parser.c +++ b/src/compiler/parser.c @@ -177,6 +177,7 @@ bool parse_stdin(void) .name = "stdin", .file_id = STDIN_FILE_ID, .full_path = "", + .dir_path = "", }; #define BUF_SIZE 65536 char buffer[BUF_SIZE];