Mike McCormack wrote:
ChangeLog:
- Add janitorial task to avoid using strncpy
Index: templates/en/janitorial.template
RCS file: /home/wine/lostwages/templates/en/janitorial.template,v retrieving revision 1.61 diff -u -r1.61 janitorial.template --- templates/en/janitorial.template 11 Jan 2005 20:33:41 -0000 1.61 +++ templates/en/janitorial.template 13 Jan 2005 15:15:44 -0000 @@ -7,6 +7,24 @@ Janitor's List</a>), and it's high time that we have one too. What is there to clean up? Well, lots of things! :)
<h2>Eliminate uses of strncpy/strncpyW</h2>
<i>strncpy(dst,src,n)</i> has two subtle
<a href="http://weblogs.asp.net/oldnewthing/archive/2005/01/07.aspx">
problems</a>. The first is that it always fills the whole <i>dst</i>
buffer (<i>n</i> characters). The second is that it doesn't always nul
terminate the <i>dst</i> buffer that it's filling.<p>
Wine code should avoid the use of strncpy for these reasons, and instead
use lstrcpyA/W or memcpy. You can use the following command to find
occurences of strncpy in the Wine source code:<p>
<tt>find . -name *.c -exec grep strncpy {} ; -ls</tt><p>
The aim is to make sure that we only copy as many bytes as necessary into
the <i>dst</i> buffer, and always nul terminate the buffer when we
intended to.<p>
<h2>Regedit fixes</h2>
Regedit lacks a few features. We need to improve regedit to:
Couldn't we just make a sane implementation of strncpy, not adding more '\0' characters than necessary and making sure the last character is an '\0'? (untested ofcourse ;))
char *strncpy(char *dst,char *src,int n) { int i; for (i = 0; (dst[i] = src[i]) != '\0' && i < n; i++) ; /* n - 1 is '\0'; ensures the end of the string is '\0' */ dst[n - 1] = '\0'; }
Now, something like this would at least save us of replacing all strncpyW, wouldn't it?
regards,
Joris