From 604e3b7dd5659efe5fd36ef8cb1c80c937b64722 Mon Sep 17 00:00:00 2001 From: bfoersterling Date: Sat, 26 Jul 2025 10:43:08 +0200 Subject: [PATCH 1/4] added generate-llvm target that creates ll files and links to a single icscli.ll --- justfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/justfile b/justfile index 7169a53..0a91110 100644 --- a/justfile +++ b/justfile @@ -17,6 +17,12 @@ test: install: default meson install -C src/builddir +[working-directory: 'src'] +generate-llvm: + clang -S -emit-llvm -std=gnu23 *.c + llvm-link -S -v *.ll -o icscli.ll + clean: rm -rf src/builddir rm -rf unit_tests/builddir + rm -f src/*.ll From 86d0cd9a6ca34317445b28fb8fac0be46e4d4a93 Mon Sep 17 00:00:00 2001 From: bfoersterling Date: Sat, 26 Jul 2025 11:04:17 +0200 Subject: [PATCH 2/4] clean before compiling to llvm ir --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index 0a91110..ac6588e 100644 --- a/justfile +++ b/justfile @@ -18,7 +18,7 @@ install: default meson install -C src/builddir [working-directory: 'src'] -generate-llvm: +generate-llvm: clean clang -S -emit-llvm -std=gnu23 *.c llvm-link -S -v *.ll -o icscli.ll From 039b77310c0e616bb26f16af19a2d16526b26318 Mon Sep 17 00:00:00 2001 From: bfoersterling Date: Mon, 28 Jul 2025 18:46:45 +0200 Subject: [PATCH 3/4] compile llvm ir to binary --- justfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/justfile b/justfile index ac6588e..e6714ac 100644 --- a/justfile +++ b/justfile @@ -22,6 +22,10 @@ generate-llvm: clean clang -S -emit-llvm -std=gnu23 *.c llvm-link -S -v *.ll -o icscli.ll +[working-directory: 'src'] +llvm-to-binary: generate-llvm + clang icscli.ll -o icscli -luuid + clean: rm -rf src/builddir rm -rf unit_tests/builddir From 25d31aaacd3cfa1e48cc9b9f49cfceda3304443d Mon Sep 17 00:00:00 2001 From: bfoersterling Date: Mon, 28 Jul 2025 19:31:07 +0200 Subject: [PATCH 4/4] fixed memory bug that only showed up when compiling with clang and on a specific ics file --- justfile | 3 ++- src/file_handling.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index e6714ac..47b9b69 100644 --- a/justfile +++ b/justfile @@ -19,7 +19,7 @@ install: default [working-directory: 'src'] generate-llvm: clean - clang -S -emit-llvm -std=gnu23 *.c + clang -g -Wall -S -emit-llvm -std=gnu23 *.c llvm-link -S -v *.ll -o icscli.ll [working-directory: 'src'] @@ -30,3 +30,4 @@ clean: rm -rf src/builddir rm -rf unit_tests/builddir rm -f src/*.ll + rm -f src/icscli diff --git a/src/file_handling.c b/src/file_handling.c index 87c0201..595f819 100644 --- a/src/file_handling.c +++ b/src/file_handling.c @@ -36,7 +36,8 @@ void read_until_string(int fd, char buffer[], char search_string[]) { i++; } size_t truncate_position = strlen(buffer) - strlen(search_string); - memset(&buffer[truncate_position], '\0', truncate_position); + + memset(&buffer[truncate_position], '\0', strlen(buffer) - truncate_position); } // Seeks for a string in an open file.