From 78f60d7e0cd8347704ea03a6fc96ef484acb8ee0 Mon Sep 17 00:00:00 2001 From: Macoy Madson Date: Sat, 2 Oct 2021 18:50:28 -0400 Subject: [PATCH 1/2] Ensure null terminator is set I'm not 100% sure of this code. --- runtime/FileUtilities.cake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/FileUtilities.cake b/runtime/FileUtilities.cake index 999dca5..8507b4b 100644 --- a/runtime/FileUtilities.cake +++ b/runtime/FileUtilities.cake @@ -122,8 +122,9 @@ (fseek in-file 0 SEEK_END) (var file-size size_t (ftell in-file)) (rewind in-file) - (var-cast-to out-buffer (* char) (malloc file-size)) + (var-cast-to out-buffer (* char) (malloc (+ 1 file-size))) (fread out-buffer file-size 1 in-file) + (set (at file-size contents-buffer) 0) (return out-buffer)) (defun write-string (out-file (* FILE) out-string (* (const char))) From e123b3337cd157201b9c28617d877df38f4c3bf8 Mon Sep 17 00:00:00 2001 From: Macoy Madson Date: Sat, 2 Oct 2021 18:51:30 -0400 Subject: [PATCH 2/2] Fix copy paste error --- runtime/FileUtilities.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/FileUtilities.cake b/runtime/FileUtilities.cake index 8507b4b..cfa3e22 100644 --- a/runtime/FileUtilities.cake +++ b/runtime/FileUtilities.cake @@ -124,7 +124,7 @@ (rewind in-file) (var-cast-to out-buffer (* char) (malloc (+ 1 file-size))) (fread out-buffer file-size 1 in-file) - (set (at file-size contents-buffer) 0) + (set (at file-size out-buffer) 0) (return out-buffer)) (defun write-string (out-file (* FILE) out-string (* (const char)))