msvcp90: Handle npos as length in more places.

This commit is contained in:
Dan Kegel 2012-09-08 07:59:44 -07:00 committed by Alexandre Julliard
parent 5befb959dd
commit 8e9e82f41e
2 changed files with 13 additions and 7 deletions

View File

@ -1331,7 +1331,7 @@ int __thiscall MSVCP_basic_string_char_compare_substr_cstr_len(
if(this->size < pos)
MSVCP__String_base_Xran();
if(pos+num > this->size)
if(num > this->size-pos)
num = this->size-pos;
ans = MSVCP_char_traits_char_compare(basic_string_char_const_ptr(this)+pos,
@ -1378,7 +1378,7 @@ int __thiscall MSVCP_basic_string_char_compare_substr_substr(
if(compare->size < off)
MSVCP__String_base_Xran();
if(off+count > compare->size)
if(count > compare->size-off)
count = compare->size-off;
return MSVCP_basic_string_char_compare_substr_cstr_len(this, pos, num,
@ -2017,7 +2017,7 @@ basic_string_char* __thiscall basic_string_char_replace_substr(basic_string_char
if(str->size < str_off)
MSVCP__String_base_Xran();
if(str_off+str_len > str->size)
if(str_len > str->size-str_off)
str_len = str->size-str_off;
return basic_string_char_replace_cstr_len(this, off, len,
@ -3265,7 +3265,7 @@ int __thiscall MSVCP_basic_string_wchar_compare_substr_cstr_len(
if(this->size < pos)
MSVCP__String_base_Xran();
if(pos+num > this->size)
if(num > this->size-pos)
num = this->size-pos;
ans = MSVCP_char_traits_wchar_compare(basic_string_wchar_const_ptr(this)+pos,
@ -3318,7 +3318,7 @@ int __thiscall MSVCP_basic_string_wchar_compare_substr_substr(
if(compare->size < off)
MSVCP__String_base_Xran();
if(off+count > compare->size)
if(count > compare->size-off)
count = compare->size-off;
return MSVCP_basic_string_wchar_compare_substr_cstr_len(this, pos, num,
@ -3980,7 +3980,7 @@ basic_string_wchar* __thiscall basic_string_wchar_replace_substr(basic_string_wc
if(str->size < str_off)
MSVCP__String_base_Xran();
if(str_off+str_len > str->size)
if(str_len > str->size-str_off)
str_len = str->size-str_off;
return basic_string_wchar_replace_cstr_len(this, off, len,

View File

@ -17,6 +17,7 @@
*/
#include <stdio.h>
#include <limits.h>
#include <windef.h>
#include <winbase.h>
@ -450,11 +451,12 @@ static void test_basic_string_char_append(void) {
}
static void test_basic_string_char_compare(void) {
basic_string_char str1, str2;
basic_string_char str1, str2, str3;
int ret;
call_func2(p_basic_string_char_ctor_cstr, &str1, "str1str");
call_func2(p_basic_string_char_ctor_cstr, &str2, "str9str");
call_func2(p_basic_string_char_ctor_cstr, &str3, "splash.png");
ret = (int)call_func6(p_basic_string_char_compare_substr_substr,
&str1, 0, 3, &str2, 0, 3);
@ -469,6 +471,9 @@ static void test_basic_string_char_compare(void) {
ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
&str1, 0, 1000, "str1str", 7);
ok(ret == 0, "ret = %d\n", ret);
ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
&str3, 6, UINT_MAX, ".png", 4);
ok(ret == 0, "ret = %d\n", ret);
ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
&str1, 1, 2, "tr", 2);
ok(ret == 0, "ret = %d\n", ret);
@ -481,6 +486,7 @@ static void test_basic_string_char_compare(void) {
call_func1(p_basic_string_char_dtor, &str1);
call_func1(p_basic_string_char_dtor, &str2);
call_func1(p_basic_string_char_dtor, &str3);
}
static void test_basic_string_char_concatenate(void) {