caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Bug value
@ 2002-02-19 12:13 Warp
  2002-02-19 12:43 ` Dmitry Lomov
  2002-02-19 14:35 ` Sven
  0 siblings, 2 replies; 3+ messages in thread
From: Warp @ 2002-02-19 12:13 UTC (permalink / raw)
  To: OCaml

Is the following code :

let read_fdata file =
 let id = (input_value file : fid) in
 let infos = (input_value file : finfos) in
 {
  id = id;
  infos = infos;
  childs = clist;
  deps = dlist;
 }

equivalent to :

let read_fdata file =
 {
  id = (input_value file : fid);
  infos = (input_value file : finfos);
 }

?
Because the first one got no problem while the second one is causing a fatal
bug at run-time when I try to access the struct

PS :
-----
type fid = int
type fver = int
type ftype = int
type finfos = {
 mutable name : string;
 mutable parent : fid;
 mutable ver : fver;
 mutable t : ftype;
}

Warp

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Bug value
  2002-02-19 12:13 [Caml-list] Bug value Warp
@ 2002-02-19 12:43 ` Dmitry Lomov
  2002-02-19 14:35 ` Sven
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Lomov @ 2002-02-19 12:43 UTC (permalink / raw)
  To: Warp; +Cc: OCaml

Hello,
I assume that the answer to you problem is that such "assignments" to record
fields
occur in order deemed convenient (read: efficient) by compiler, and not
necessarily in
the order you write them in your code.

In the second snippet, compiler probably generates code in such a way that
(input_value file : finfos) occurs before (input_value file : fid).

The first snippet is _the_ way in OCaml to ensure the order of execution of
functions
with side effects, like input_value.

Hope this helps,
Friendly,
Dmitry


----- Original Message -----
From: "Warp" <warplayer@free.fr>
To: "OCaml" <caml-list@inria.fr>
Sent: Tuesday, February 19, 2002 2:13 PM
Subject: [Caml-list] Bug value


> Is the following code :
>
> let read_fdata file =
>  let id = (input_value file : fid) in
>  let infos = (input_value file : finfos) in
>  {
>   id = id;
>   infos = infos;
>   childs = clist;
>   deps = dlist;
>  }
>
> equivalent to :
>
> let read_fdata file =
>  {
>   id = (input_value file : fid);
>   infos = (input_value file : finfos);
>  }
>
> ?
> Because the first one got no problem while the second one is causing a
fatal
> bug at run-time when I try to access the struct
>
> PS :
> -----
> type fid = int
> type fver = int
> type ftype = int
> type finfos = {
>  mutable name : string;
>  mutable parent : fid;
>  mutable ver : fver;
>  mutable t : ftype;
> }
>
> Warp
>
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives:
http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ:
http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Bug value
  2002-02-19 12:13 [Caml-list] Bug value Warp
  2002-02-19 12:43 ` Dmitry Lomov
@ 2002-02-19 14:35 ` Sven
  1 sibling, 0 replies; 3+ messages in thread
From: Sven @ 2002-02-19 14:35 UTC (permalink / raw)
  To: Warp; +Cc: OCaml

On Tue, Feb 19, 2002 at 01:13:59PM +0100, Warp wrote:
> Is the following code :
> 
> let read_fdata file =
>  let id = (input_value file : fid) in
>  let infos = (input_value file : finfos) in
>  {
>   id = id;
>   infos = infos;
>   childs = clist;
>   deps = dlist;
>  }
> 
> equivalent to :
> 
> let read_fdata file =
>  {
>   id = (input_value file : fid);
>   infos = (input_value file : finfos);
>  }
> 
> ?
> Because the first one got no problem while the second one is causing a fatal
> bug at run-time when I try to access the struct

Mmm, my guess is that the first one is done in order, while the second one is
done from the last field to the first, not sure though.

As such, it can happen that you did write a fid (which is an int) while you
try to read a finfos first, and thus this cause problems.

You could try inverting the order of the id = and infos =, but again, this is
not guaranteed to work on all implementations of ocaml (or even between
different versions), and as thus is discouraged, i think.

The file ios are insecure, which cause the problem to be detected at runtime,
and not at compile time. There was work from Jun about securing this kind of
thing, but i guess it never made it into the official release of ocaml.

Friendly,

Sven Luther
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2002-02-19 14:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-19 12:13 [Caml-list] Bug value Warp
2002-02-19 12:43 ` Dmitry Lomov
2002-02-19 14:35 ` Sven

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).