From: Nicolas Trangez <nicolas@incubaid.com>
To: caml-list@inria.fr
Subject: [Caml-list] Bug in caml_string_get16?
Date: Mon, 04 Nov 2013 23:54:22 +0100 [thread overview]
Message-ID: <1383605662.24373.7.camel@tau.nicolast.be> (raw)
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
next reply other threads:[~2013-11-04 22:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-04 22:54 Nicolas Trangez [this message]
2013-11-05 3:54 ` Ivan Gotovchits
2013-11-05 9:53 ` Nicolas Trangez
2013-11-05 10:49 ` Gabriel Scherer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383605662.24373.7.camel@tau.nicolast.be \
--to=nicolas@incubaid.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox