From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Nicolas Trangez <nicolas@incubaid.com>
Cc: Ivan Gotovchits <ivg@ieee.org>, caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Bug in caml_string_get16?
Date: Tue, 5 Nov 2013 11:49:51 +0100 [thread overview]
Message-ID: <CAPFanBHbKtUixgi5E50c3OhJORL+qJDwx4jcj2UypfGJTnodZA@mail.gmail.com> (raw)
In-Reply-To: <1383645204.20247.1.camel@tau.nicolast.be>
Despite the somewhat unclear reporting (I didn't read the first mail
carefully enough to understand the problem), this is in fact a
report for a very serious bug. I have a fix in the works that should
end upstream quickly.
OCaml version 4.01.0
# external set64 : string -> int -> int -> unit = "caml_string_set64";;
external set64 : string -> int -> int -> unit = "caml_string_set64"
# set64 "0" 1 42;;
zsh: segmentation fault
On Tue, Nov 5, 2013 at 10:53 AM, Nicolas Trangez <nicolas@incubaid.com> wrote:
> On Tue, 2013-11-05 at 07:54 +0400, Ivan Gotovchits wrote:
>> Nicolas Trangez <nicolas@incubaid.com> writes:
>>
>> > What would you expect to be the output of this code?
>>
>> It should fail :)
>>
>> In a string literal any symbol that you can type with your keyboard is
>> stored in a special encoding called ASCII. With "1" you have just
>> created a string containig a single byte with a value 49. So, first off
>> all, your string is too short, because it has length of 1, when int16
>> obviously needs two bytes of storage space. If you really interested,
>> binary 1 will be represented in a memory of a little endian computer
>> like this: "\x01\x00". The special escape symbol "\" allows us to type
>> untypable. The the code
>>
>> open EndianString
>> let d = LittleEndian.get_int16 "\x01\x00" 0
>>
>> will yield:
>>
>> val d : int = 1
>>
>> By the way, if we try your string (with a more correct invocation):
>>
>> open EndianString
>> let d = LittleEndian.get_int8 "1" 0
>>
>> we will got:
>>
>> val d : int = 49
>>
>> Futher reading:
>>
>> 1. man ascii
>> 2. wikipedia article on endianess
>
> Oh, don't be mistaken. The question was rhetorical, in order to report a
> bug (or get told it's not a bug at all) & provide a test-case :-)
> I'm well aware of all of the above ;-)
>
> Thanks!
>
> Nicolas
>
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
prev parent reply other threads:[~2013-11-05 10:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-04 22:54 Nicolas Trangez
2013-11-05 3:54 ` Ivan Gotovchits
2013-11-05 9:53 ` Nicolas Trangez
2013-11-05 10:49 ` Gabriel Scherer [this message]
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=CAPFanBHbKtUixgi5E50c3OhJORL+qJDwx4jcj2UypfGJTnodZA@mail.gmail.com \
--to=gabriel.scherer@gmail.com \
--cc=caml-list@inria.fr \
--cc=ivg@ieee.org \
--cc=nicolas@incubaid.com \
/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