Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Bug value
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sven <luther@d...>
Subject: Re: [Caml-list] Bug value
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