/dlls/msvcrt/string.c: _strnset() returns wrong value

Ralf Bittmann rbittmann at web.de
Thu Oct 14 16:35:59 CDT 2004


your implementation of _strnset() is different from that of
microsoft: the return value is not the same (see below).


1. wine code (wine-20040914\dlls\msvcrt\string.c)
   returns a 'working' pointer:
/*********************************************************************
 *  _strnset (MSVCRT.@)
 */
char* _strnset(char* str, int value, unsigned int len)
{
  if (len > 0 && str)
    while (*str && len--)
      *str++ = value;
  return str;
}


2. microsoft code (msvcrt.dll, 6.10.8637.0)
   returns the same pointer, that was given as argument:
;*********************************************************************
; char* __cdecl strnset(char *str, int value, unsigned int len)
                public _strnset
_strnset        proc near
                push    ebp
                mov     ebp, esp
                push    edi
                push    ebx
                mov     edi, [ebp+8]         ;edi=str
                mov     edx, edi             ;edx=edi
                mov     ebx, [ebp+10h]       ;ebx=len
                xor     eax, eax
                mov     ecx, ebx
                jecxz   short loc_exit       ;if(len==0) goto loc_exit
                repne scasb
                jnz     short loc_here
                inc     ecx
loc_here:
                sub     ebx, ecx
                mov     ecx, ebx
                mov     edi, edx
                mov     al, [ebp+0Ch]
                repe stosb
loc_exit:
                mov     eax, edx             ;return (unmodified) edx
                pop     ebx
                pop     edi
                leave
                retn
_strnset        endp


3. patched code (i'm sorry, i don't have DIFF by my side)
   returns the same pointer, that was given as argument:
/*********************************************************************
 *  _strnset (MSVCRT.@)
 */
char* _strnset(char* str, int value, unsigned int len)
{
  char *ret = str;
  if (len && str)
    while (*str && len--)
      *str++ = value;
  return ret;
}



change log entry:
dlls/msvcrt/string.c: Ralf Bittmann <rbittmann at web.de>
Proper return value in _strnset.



More information about the wine-patches mailing list