Skip to content

Commit 3ab4520

Browse files
ushitora-anqouvbmithr
authored andcommitted
fix: don't use Bytes.unsafe_{of,to}_string for not owned strings
1 parent b1854e9 commit 3ab4520

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: core/websocket.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module Frame = struct
9090
{ opcode; extension; final; content }
9191

9292
let of_bytes ?opcode ?extension ?final content =
93-
let content = Bytes.unsafe_to_string content in
93+
let content = Bytes.to_string content in
9494
create ?opcode ?extension ?final ~content ()
9595

9696
let close code =
@@ -227,7 +227,7 @@ module Make (IO : Cohttp.S.IO) = struct
227227
let write_frame_to_buf ~mode buf fr =
228228
let scratch = Bytes.create 8 in
229229
let open Frame in
230-
let content = Bytes.unsafe_of_string fr.content in
230+
let content = Bytes.of_string fr.content in
231231
let len = Bytes.length content in
232232
let opcode = Opcode.to_enum fr.opcode in
233233
let payload_len =
@@ -310,7 +310,7 @@ module Make (IO : Cohttp.S.IO) = struct
310310
match payload with
311311
| None -> proto_error "could not read payload (len=%d)" payload_len
312312
| Some payload ->
313-
let payload = Bytes.unsafe_of_string payload in
313+
let payload = Bytes.of_string payload in
314314
if frame_masked then xor mask payload;
315315
let frame = Frame.of_bytes ~opcode ~extension ~final payload in
316316
return frame)

0 commit comments

Comments
 (0)