cleanup a->w cross calls in advapi32/crypt.c

James Hawkins truiken at gmail.com
Mon Aug 2 12:18:04 CDT 2004


> -             strcpy(keyname + strlen(KEYSTR), pProvName);
I changed that line to strcatW(keyname, pProvName).  That makes a lot
more sense Mike, thanks for the tip.

I'm wasn't exactly sure on this one so it would be great if you could
help me on this one.  When using pointer arithmetic, do the operations
such as --, ++... increment or decrement by the size of the pointer
type?  For example,

*(ptr - sizeof(WCHAR)) = (dwType % 10) + '0';
*(ptr - sizeof(WCHAR) * 2) = ((dwType / 10) % 10) + '0';
*(ptr - sizeof(WCHAR) * 3) = (dwType / 100) + '0';

Is the sizeof(WCHAR) multiplication redundant because --ptr actually
moves ptr down one WCHAR?  I understand that if that's the case, but
what about when the pointer is first initialized?

ptr = keyname + strlenW(keyname);

I guess it holds true here as well because keyname is a pointer and
we're adding ot it.  If that is the case, the included patch fixes the
two things mentioned.

On Mon, 02 Aug 2004 19:55:12 +0900, Mike McCormack <mike at codeweavers.com> wrote:
> 
> James Hawkins wrote:
> 
> > +        PWSTR keyname;
> >
> > -     keyname = CRYPT_Alloc(strlen(KEYSTR) + strlen(pProvName) +1);
> > +        keyname = CRYPT_Alloc((strlenW(KEYSTR) + strlenW(pProvName) + 1) * sizeof(WCHAR));
> >       if (keyname)
> >       {
> > -             strcpy(keyname, KEYSTR);
> > -             strcpy(keyname + strlen(KEYSTR), pProvName);
> > +             strcpyW(keyname, KEYSTR);
> > +             strcpyW(keyname + strlenW(KEYSTR) * sizeof(WCHAR), pProvName);
> >       } else
> >               SetLastError(ERROR_NOT_ENOUGH_MEMORY);
> >       return keyname;
> >  }
> 
> This doesn't look right.... when using pointer arithmetic, you do so in
> increments of the pointer's type (eg. WCHAR). The following two lines
> are the same, and are both wrong:
> 
>    strcpyW(keyname + strlenW(KEYSTR) * sizeof(WCHAR), pProvName);
>    strcpyW(&keyname[strlenW(KEYSTR) * sizeof(WCHAR)], pProvName);
> 
> The right version would be:
> 
>    strcpyW(&keyname[strlenW(KEYSTR)], pProvName);
> 
> but how about just using:
> 
>    strcatW( keyname, pProvname );
> 
> Mike
> 


-- 
James Hawkins
-------------- next part --------------
A non-text attachment was scrubbed...
Name: advapi32-crypt-cross.diff
Type: text/x-patch
Size: 28090 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20040802/37fccbe4/advapi32-crypt-cross.bin


More information about the wine-devel mailing list