Re: msvcrt: do not overlap in strcpy (valgrind) (try 2)

View: New views
3 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: msvcrt: do not overlap in strcpy (valgrind) (try 2)

by Vitaliy Margolen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

André Hentschel wrote:

>
> diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
> index 010e1a6..08eaf73 100644
> --- a/dlls/msvcrt/math.c
> +++ b/dlls/msvcrt/math.c
> @@ -856,7 +856,7 @@ char * CDECL _ecvt( double number, int ndigits, int *decpt, int *sign )
>      snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
>      /* take the decimal "point away */
>      if( prec != 1)
> -        strcpy( data->efcvt_buffer + 1, data->efcvt_buffer + 2);
> +        memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, strlen(data->efcvt_buffer) );
You don't need additional strlen. You already have a length from snprintf
(that's returned but not assigned to anything).

Vitaliy.




Re: msvcrt: do not overlap in strcpy (valgrind) (try 2)

by André Hentschel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Vitaliy Margolen schrieb:

> André Hentschel wrote:
>> diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
>> index 010e1a6..08eaf73 100644
>> --- a/dlls/msvcrt/math.c
>> +++ b/dlls/msvcrt/math.c
>> @@ -856,7 +856,7 @@ char * CDECL _ecvt( double number, int ndigits, int *decpt, int *sign )
>>      snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
>>      /* take the decimal "point away */
>>      if( prec != 1)
>> -        strcpy( data->efcvt_buffer + 1, data->efcvt_buffer + 2);
>> +        memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, strlen(data->efcvt_buffer) );
> You don't need additional strlen. You already have a length from snprintf
> (that's returned but not assigned to anything).
>
> Vitaliy.
>
>
>
thx again, really didnt got that.

--

Best Regards, André Hentschel



Re: msvcrt: do not overlap in strcpy (valgrind) (try 2)

by Vitaliy Margolen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

André Hentschel wrote:

> Vitaliy Margolen schrieb:
>> André Hentschel wrote:
>>> diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
>>> index 010e1a6..08eaf73 100644
>>> --- a/dlls/msvcrt/math.c
>>> +++ b/dlls/msvcrt/math.c
>>> @@ -856,7 +856,7 @@ char * CDECL _ecvt( double number, int ndigits, int *decpt, int *sign )
>>>      snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
>>>      /* take the decimal "point away */
>>>      if( prec != 1)
>>> -        strcpy( data->efcvt_buffer + 1, data->efcvt_buffer + 2);
>>> +        memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, strlen(data->efcvt_buffer) );
>> You don't need additional strlen. You already have a length from snprintf
>> (that's returned but not assigned to anything).
>>
>>
> thx again, really didnt got that.
>
> -        strcpy( data->efcvt_buffer + 1, data->efcvt_buffer + 2);
> +        memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, len );

You still have a problem here. You moving 1 byte too many. Remember, memmove
is not a string function and doesn't care about '\0' characters.

Vitaliy.