VN -

On Tue, Dec 22, 2009 at 1:45 AM, Gabriel Kerneis <kern...@pps.jussieu.fr>wrote:

> On Mon, Dec 21, 2009 at 11:54:51PM -0700, ThanhVu (Vu) Nguyen wrote:
> > if the program is
> > char dest [100] = "";
> > char *src = "hello world";
> > sprintf(dest,src);
> > so if I want to change it to
> > snprintf(dest,src,sizeof(dest));
> > then I am not sure which SizeOf to use ?  should I use AddressOf
> something
> > here?
>
> SizeOf is always the good one, provided you are facing a statically
> declared array (whose length is known at compile time).  On the other
> hand, if you face a pointer to some area, you have no way to guess the
> good value (and sizeof will always return the size of a pointer, ie 4 or
> 8 depending on your architecture).  This is the whole point in using
> snprintf: it's a piece of information that the compiler cannot figure
> out automatically, so we force the programmer to think about it and pass
> the (hopefully) correct value to snprintf.  CIL won't be of any help
> here.
>

Did you mean "SizeOfE" ?  because  SizeOf needs a "typ"  but I only have the
expression.  Should I use typeOf to get the type of that expression ?
e.g.,  SizeOf (typeOf(exp))  ?

    let strncpy_va = makeVarinfo true "strncpy" (TVoid []) in
    match instr with
      |Call(lhs,Lval(Var {vname="strcpy"},nos),[dest;src],loc)->
         let new_instr =
           Call(lhs,Lval((Var strncpy_va),nos), [dest;src;(SizeOfE
dest)],loc) in


 Thanks
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to