From e935f8e2ffc19294573025287a08dcbe9137e282 Mon Sep 17 00:00:00 2001 From: Zac Pierson Date: Tue, 21 Mar 2017 16:00:11 -0500 Subject: [PATCH] Fixed os_linux and os_x read_entire_file function not null-terminating data. --- core/os_linux.odin | 3 ++- core/os_x.odin | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/os_linux.odin b/core/os_linux.odin index 0fd8287ce..52b9dad51 100644 --- a/core/os_linux.odin +++ b/core/os_linux.odin @@ -146,13 +146,14 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) { // We have a file size! - data := new_slice(u8, size); + data := new_slice(u8, size+1); if data.data == nil { fmt.println("Failed to allocate file buffer."); return nil, false; } read(handle, data); + data[size] = 0; return data, true; } diff --git a/core/os_x.odin b/core/os_x.odin index c665b533d..6133bce7c 100644 --- a/core/os_x.odin +++ b/core/os_x.odin @@ -150,13 +150,14 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) { // We have a file size! - data := new_slice(u8, size); + data := new_slice(u8, size+1); if data.data == nil { fmt.println("Failed to allocate file buffer."); return nil, false; } read(handle, data); + data[size] = 0; return data, true; }