Skip to content

Latest commit

 

History

History
39 lines (24 loc) · 637 Bytes

OCaml.md

File metadata and controls

39 lines (24 loc) · 637 Bytes

Table of Contents

OCaml

Poisoning


Strings are passed by reference

let check c =
  if c then "OK" else "KO";;

let f=check false in
  f.[0]<-'O'; f.[1]<-'K';;

check true;;
check false;;

Expected result: OK then KO

Result: OK twice

Reason: the returned value from check is a reference to the string, and can be modified. The code in lines 4-5 change KO to OK.

Solution: use the -safe-string compiler flag

Tested with: OCaml 4.02.3