Safe-string fixes.

This commit is contained in:
Richard W.M. Jones 2017-11-18 12:49:35 +00:00
parent 1c10a9c1ce
commit 5d5776d91a
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,61 @@
diff -ur bin_prot-2.0.9.old/lib/common.ml bin_prot-2.0.9/lib/common.ml
--- bin_prot-2.0.9.old/lib/common.ml 2012-03-15 19:59:16.000000000 +0000
+++ bin_prot-2.0.9/lib/common.ml 2017-11-18 12:44:52.543443638 +0000
@@ -165,7 +165,7 @@
else unsafe_blit_string_buf ~src_pos str ~dst_pos buf ~len)
external unsafe_blit_buf_string :
- src_pos : int -> buf -> dst_pos : int -> string -> len : int -> unit
+ src_pos : int -> buf -> dst_pos : int -> bytes -> len : int -> unit
= "bin_prot_blit_buf_string_stub" "noalloc"
let blit_buf_string ?src_pos buf ?dst_pos str ~len =
@@ -176,12 +176,12 @@
else if len = 0 then (
if src_pos > Array1.dim buf then
invalid_arg "Bin_prot.Common.blit_buf_string: src_pos > buf_len";
- if dst_pos > String.length str then
+ if dst_pos > Bytes.length str then
invalid_arg "Bin_prot.Common.blit_buf_string: src_pos > str_len")
else (
if src_pos + len > Array1.dim buf then
invalid_arg "Bin_prot.Common.blit_buf_string: src_pos + len > buf_len"
- else if dst_pos + len > String.length str then
+ else if dst_pos + len > Bytes.length str then
invalid_arg "Bin_prot.Common.blit_buf_string: src_pos + len > str_len"
else unsafe_blit_buf_string ~src_pos buf ~dst_pos str ~len)
diff -ur bin_prot-2.0.9.old/lib/common.mli bin_prot-2.0.9/lib/common.mli
--- bin_prot-2.0.9.old/lib/common.mli 2012-03-15 19:59:16.000000000 +0000
+++ bin_prot-2.0.9/lib/common.mli 2017-11-18 12:45:38.015421813 +0000
@@ -63,7 +63,7 @@
*)
val blit_buf_string :
- ?src_pos : int -> buf -> ?dst_pos : int -> string -> len : int -> unit
+ ?src_pos : int -> buf -> ?dst_pos : int -> bytes -> len : int -> unit
(** [blit_buf_string ?src_pos src ?dst_pos dst ~len] blits [len]
bytes of the source buffer [src] starting at position [src_pos]
to string [dst] starting at position [dst_pos].
@@ -181,5 +181,5 @@
= "bin_prot_blit_string_buf_stub" "noalloc"
external unsafe_blit_buf_string :
- src_pos : int -> buf -> dst_pos : int -> string -> len : int -> unit
+ src_pos : int -> buf -> dst_pos : int -> bytes -> len : int -> unit
= "bin_prot_blit_buf_string_stub" "noalloc"
diff -ur bin_prot-2.0.9.old/lib/read_ml.ml bin_prot-2.0.9/lib/read_ml.ml
--- bin_prot-2.0.9.old/lib/read_ml.ml 2012-03-15 19:59:16.000000000 +0000
+++ bin_prot-2.0.9/lib/read_ml.ml 2017-11-18 12:47:01.188381893 +0000
@@ -225,9 +225,9 @@
let next = pos + len in
check_next buf next;
pos_ref := next;
- let str = String.create len in
+ let str = Bytes.create len in
unsafe_blit_buf_string ~src_pos:pos buf ~dst_pos:0 str ~len;
- str
+ Bytes.to_string str
let bin_read_char (buf : buf) ~pos_ref =
let pos = safe_get_pos buf pos_ref in

View File

@ -17,6 +17,9 @@ Patch1: %{name}-2.0.9-remove-Werror.patch
# Update integer types for ocaml 4.02
Patch2: %{name}-2.0.9-fix-ints.patch
# Safe-string fixes for OCaml 4.06.
Patch3: bin-prot-2.0.9-safe-string.patch
BuildRequires: ocaml >= 3.12.0
BuildRequires: ocaml-ocamlbuild
BuildRequires: ocaml-findlib-devel
@ -55,6 +58,7 @@ developing applications that use %{name}.
%setup -q -n bin_prot-%{version}
%patch1 -p1
%patch2 -p1
%patch3 -p1
# Use Fedora CFLAGS, and define ARCH_INT64_TYPE
expr=' "-DARCH_INT64_TYPE";'