Blame SOURCES/0019-Fixes-for-safe-string-in-OCaml-4.06.patch

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