[dlls/msi/*] Strncpy elimination.

Peter Berg Larsen pebl at math.ku.dk
Mon Mar 28 10:33:52 CST 2005


On Mon, 28 Mar 2005, Jakob Eriksson wrote:

> Good thing you sent these patches.  I was just thinking, should I dig
> in? :-)

You could recheck them? I tend to get code blind, when having so many
cases that nearly are identical. As I said there are probably one two
places where I didnt get the sematic of the code. Especially look for
off-by-one (\0) when the replacement is a memcpy. I tend to do this,
because of codestyle, like:


> >+++ dlls/msi/dialog.c	26 Mar 2005 09:40:51 -0000
> >@@ -131,7 +131,7 @@
> >     ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
> >     if( !ret )
> >         return ret;
> >-    strncpyW( ret, p, len );
> >+    memcpy( ret, p, len*sizeof(WCHAR) );
> >     ret[len-1] = 0;
> >     return ret;
> > }

This memcpyies one element more than needed.. but seemed much nicer than
memcpy( ret, p, (len - 1)*sizeof(WHCAR);

I probably should have subtracted one from len, making it obvious
that this is a strdupW, like:
  ret = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
  memcpy( ret, p, len*sizeof(WCHAR) );
  ret[len] = 0;

Peter




More information about the wine-devel mailing list