2
0
Эх сурвалжийг харах

Fixed os_linux and os_x read_entire_file function not null-terminating data.

Zac Pierson 8 жил өмнө
parent
commit
e935f8e2ff
2 өөрчлөгдсөн 4 нэмэгдсэн , 2 устгасан
  1. 2 1
      core/os_linux.odin
  2. 2 1
      core/os_x.odin

+ 2 - 1
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;
 }

+ 2 - 1
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;
 }