43 lines
1.2 KiB
Diff
43 lines
1.2 KiB
Diff
From 2d8ef8a4ca613ad291bc05a4e5ebdc11c3eae6b9 Mon Sep 17 00:00:00 2001
|
|
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
Date: Sat, 18 Nov 2017 12:01:34 +0000
|
|
Subject: [PATCH 19/23] Fixes for -safe-string in OCaml 4.06.
|
|
|
|
---
|
|
src/top.ml | 13 ++++++++-----
|
|
1 file changed, 8 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/src/top.ml b/src/top.ml
|
|
index e2a93d6..d4f7697 100644
|
|
--- a/src/top.ml
|
|
+++ b/src/top.ml
|
|
@@ -296,17 +296,20 @@ let millisleep n =
|
|
*)
|
|
let get_string maxlen =
|
|
ignore (echo ());
|
|
- let str = String.create maxlen in
|
|
- let ok = getstr str in (* Safe because binding calls getnstr. *)
|
|
+ let str = Bytes.create maxlen in
|
|
+ (* Safe because binding calls getnstr. However the unsafe cast
|
|
+ * to string is required because ocaml-curses needs to be fixed.
|
|
+ *)
|
|
+ let ok = getstr (Obj.magic str) in
|
|
ignore (noecho ());
|
|
if not ok then ""
|
|
else (
|
|
(* Chop at first '\0'. *)
|
|
try
|
|
- let i = String.index str '\000' in
|
|
- String.sub str 0 i
|
|
+ let i = Bytes.index str '\000' in
|
|
+ Bytes.sub_string str 0 i
|
|
with
|
|
- Not_found -> str (* it is full maxlen bytes *)
|
|
+ Not_found -> Bytes.to_string str (* it is full maxlen bytes *)
|
|
)
|
|
|
|
(* Main loop. *)
|
|
--
|
|
2.31.1
|
|
|