From d1ce7c18441555cb81e28b9ebf92a50b3b6264e2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 8 Nov 2017 18:07:05 +0000 Subject: [PATCH] Fix string mutability. --- ...enerator-Use-Bytes-instead-of-String.patch | 37 +++++++++++++++++++ ...0_write.ml-Use-Bytes-instead-of-Stri.patch | 33 +++++++++++++++++ hivex.spec | 10 +++-- 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 0001-generator-Use-Bytes-instead-of-String.patch create mode 100644 0002-ocaml-t-hivex_200_write.ml-Use-Bytes-instead-of-Stri.patch diff --git a/0001-generator-Use-Bytes-instead-of-String.patch b/0001-generator-Use-Bytes-instead-of-String.patch new file mode 100644 index 0000000..9290873 --- /dev/null +++ b/0001-generator-Use-Bytes-instead-of-String.patch @@ -0,0 +1,37 @@ +From 87de49cebbf028ebb0f9950ab9e8fed97807c86e Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Wed, 8 Nov 2017 18:04:15 +0000 +Subject: [PATCH 1/2] generator: Use Bytes instead of String. + +--- + generator/generator.ml | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/generator/generator.ml b/generator/generator.ml +index 4125ae7..0401217 100755 +--- a/generator/generator.ml ++++ b/generator/generator.ml +@@ -415,15 +415,15 @@ let failwithf fs = ksprintf failwith fs + let unique = let i = ref 0 in fun () -> incr i; !i + + let replace_char s c1 c2 = +- let s2 = String.copy s in ++ let s2 = Bytes.of_string s in + let r = ref false in +- for i = 0 to String.length s2 - 1 do +- if String.unsafe_get s2 i = c1 then ( +- String.unsafe_set s2 i c2; ++ for i = 0 to String.length s - 1 do ++ if String.unsafe_get s i = c1 then ( ++ Bytes.unsafe_set s2 i c2; + r := true + ) + done; +- if not !r then s else s2 ++ if not !r then s else Bytes.to_string s2 + + let isspace c = + c = ' ' +-- +2.13.1 + diff --git a/0002-ocaml-t-hivex_200_write.ml-Use-Bytes-instead-of-Stri.patch b/0002-ocaml-t-hivex_200_write.ml-Use-Bytes-instead-of-Stri.patch new file mode 100644 index 0000000..6e4e057 --- /dev/null +++ b/0002-ocaml-t-hivex_200_write.ml-Use-Bytes-instead-of-Stri.patch @@ -0,0 +1,33 @@ +From f45648c58c18f35507475363e12a33589fb6a5f2 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Wed, 8 Nov 2017 18:05:31 +0000 +Subject: [PATCH 2/2] ocaml/t/hivex_200_write.ml: Use Bytes instead of String. + +--- + ocaml/t/hivex_200_write.ml | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/ocaml/t/hivex_200_write.ml b/ocaml/t/hivex_200_write.ml +index f70deee..97d9597 100644 +--- a/ocaml/t/hivex_200_write.ml ++++ b/ocaml/t/hivex_200_write.ml +@@ -55,14 +55,14 @@ let () = + and utf16le_of_ascii str = + let len = String.length str in + let len' = len * 2 + 2 in +- let str' = String.create len' in ++ let str' = Bytes.create len' in + for i = 0 to len-1 do + str'.[i*2] <- str.[i]; + str'.[i*2+1] <- '\000' + done; + str'.[len'-2] <- '\000'; + str'.[len'-1] <- '\000'; +- str' ++ Bytes.to_string str' + in + iter 0 0 (Hivex.root h); + +-- +2.13.1 + diff --git a/hivex.spec b/hivex.spec index b939127..118f054 100644 --- a/hivex.spec +++ b/hivex.spec @@ -26,6 +26,10 @@ Source1: http://libguestfs.org/download/hivex/%{name}-%{version}.tar.gz.s Source2: libguestfs.keyring %endif +# Upstream patches to fix string mutability. +Patch1: 0001-generator-Use-Bytes-instead-of-String.patch +Patch2: 0002-ocaml-t-hivex_200_write.ml-Use-Bytes-instead-of-Stri.patch + BuildRequires: perl-interpreter BuildRequires: perl-devel BuildRequires: perl-generators @@ -194,6 +198,7 @@ tmphome="$(mktemp -d)" gpgv2 --homedir "$tmphome" --keyring %{SOURCE2} %{SOURCE1} %{SOURCE0} %endif %setup -q +%autopatch -p1 # Build Python 3 bindings in a separate subdirectory. We have to # build everything twice unfortunately. @@ -324,10 +329,7 @@ popd %changelog * Wed Nov 08 2017 Richard W.M. Jones - 1.3.14-12 -- Bump release and rebuild. - -* Wed Nov 08 2017 Richard W.M. Jones - 1.3.14-11 -- Bump release and rebuild. +- Fix string mutability. * Wed Nov 08 2017 Richard W.M. Jones - 1.3.14-10 - OCaml 4.06.0 rebuild.