caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Bug in caml_string_get16?
@ 2013-11-04 22:54 Nicolas Trangez
  2013-11-05  3:54 ` Ivan Gotovchits
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Trangez @ 2013-11-04 22:54 UTC (permalink / raw)
  To: caml-list

All,

I was playing around with *ocplib-endian* a couple of days ago (to
access the `%caml_string_getN` primops), and found something strange
going on (which I think might be a bug).

What would you expect to be the output of this code?

```ocaml
external get_16 : string -> int -> int = "%caml_string_get16"

let main () =
  let () = try
    let i = get_16 "1" 0 in
    Printf.printf "Uh-oh 1: %d\n" i
  with exn ->
    Printf.printf "Got %s :-)\n" (Printexc.to_string exn)
  in

  try
    let i = get_16 "" 0 in
    Printf.printf "Uh-oh 2: %d\n" i
  with exn ->
    Printf.printf "Got %s :-)\n" (Printexc.to_string exn)
;;

main ()
```

Here's what it does on my system:

```
$ ocamlopt -version
4.01.0
$ ocamlbuild -use-ocamlfind parse.native
Finished, 4 targets (0 cached) in 00:00:00.
$ ./parse.native 
Got Invalid_argument("index out of bounds") :-)
Uh-oh 2: 0
```

I think there's something fishy going on here...

I didn't test, but I guess other related functions (32/64 bit & unsafe
variants) could be affected as well.

Nicolas


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-05 10:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-04 22:54 [Caml-list] Bug in caml_string_get16? Nicolas Trangez
2013-11-05  3:54 ` Ivan Gotovchits
2013-11-05  9:53   ` Nicolas Trangez
2013-11-05 10:49     ` Gabriel Scherer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).