Skip to content

Commit

Permalink
fix: remove "unsafe" function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
eWert-Online committed Sep 27, 2024
1 parent 0e9bf87 commit 5049f05
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/OSnap_Browser/Zip.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let read_4_bytes_int ic =
let read_string ic len =
let buf = Bytes.create len in
really_input ic buf 0 len;
Bytes.unsafe_to_string buf
Bytes.to_string buf
;;

let int64_of_uint32 n = Int64.(logand (of_int32 n) 0xFFFF_FFFFL)
Expand Down
13 changes: 5 additions & 8 deletions lib/OSnap_Diff/OSnap_Diff.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ let diff
if col >= original_image_start
&& col < original_image_end
&& row < original_image.height
then Array1.unsafe_get original_image.image ((row * original_image.width) + col)
then Array1.get original_image.image ((row * original_image.width) + col)
else if col > diff_mask_start && col < diff_mask_end
then (
let diff_pixel =
if row < diff_mask.height
then
Array1.unsafe_get
Array1.get
diff_mask.image
((row * diff_mask.width) + (col - diff_mask_start))
else 0x00000000l
Expand All @@ -90,7 +90,7 @@ let diff
then diff_pixel
else (
let pixel =
Array1.unsafe_get
Array1.get
original_image.image
((row * original_image.width) + (col - diff_mask_start))
|> Int32.to_int
Expand All @@ -107,13 +107,10 @@ let diff
let r = (mono land 0xFF) lsl 0 in
Int32.of_int (a lor b lor g lor r)))
else if col > new_image_start && col <= new_image_end && row < new_image.height
then
Array1.unsafe_get
new_image.image
((row * new_image.width) + (col - new_image_start))
then Array1.get new_image.image ((row * new_image.width) + (col - new_image_start))
else 0x00000000l
in
Array1.unsafe_set complete_image offset fill_with
Array1.set complete_image offset fill_with
done;
free_images ();
Osnap_Diff_Png.PngIo.write_png_bigarray
Expand Down
4 changes: 2 additions & 2 deletions lib/OSnap_Diff/png/Osnap_Diff_Png.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ module IO = struct

let readDirectPixel ~(x : int) ~(y : int) (img : t ImageIO.img) =
let image = (img.image : data) in
Array1.unsafe_get image ((y * img.width) + x)
Array1.get image ((y * img.width) + x)
;;

let setImgColor ~x ~y color (img : t ImageIO.img) =
let image = (img.image : data) in
Array1.unsafe_set image ((y * img.width) + x) color
Array1.set image ((y * img.width) + x) color
;;

let loadImage buffer : t ImageIO.img =
Expand Down

0 comments on commit 5049f05

Please sign in to comment.