Commit 0f81fcb0 authored by Alexandre Julliard's avatar Alexandre Julliard

msvcp90: Call the appropriate secure function instead of duplicating the checks.

parent b88630a4
......@@ -109,14 +109,8 @@ MSVCP_size_t CDECL MSVCP_char_traits_char_length(const char *str)
char* CDECL MSVCP_char_traits_char__Copy_s(char *dest,
MSVCP_size_t size, const char *src, MSVCP_size_t count)
{
if(!dest || !src || size<count) {
if(dest && size)
dest[0] = '\0';
_invalid_parameter(NULL, NULL, NULL, 0, 0);
return dest;
}
return memcpy(dest, src, count);
memcpy_s(dest, size, src, count);
return dest;
}
/* ?copy@?$char_traits@D@std@@SAPADPADPBDI@Z */
......@@ -140,14 +134,8 @@ const char * CDECL MSVCP_char_traits_char_find(
char* CDECL MSVCP_char_traits_char__Move_s(char *dest,
MSVCP_size_t size, const char *src, MSVCP_size_t count)
{
if(!dest || !src || size<count) {
if(dest && size)
dest[0] = '\0';
_invalid_parameter(NULL, NULL, NULL, 0, 0);
return dest;
}
return memmove(dest, src, count);
memmove_s(dest, size, src, count);
return dest;
}
/* ?move@?$char_traits@D@std@@SAPADPADPBDI@Z */
......@@ -245,14 +233,8 @@ MSVCP_size_t CDECL MSVCP_char_traits_wchar_length(const wchar_t *str)
wchar_t* CDECL MSVCP_char_traits_wchar__Copy_s(wchar_t *dest,
MSVCP_size_t size, const wchar_t *src, MSVCP_size_t count)
{
if(!dest || !src || size<count) {
if(dest && size)
dest[0] = '\0';
_invalid_parameter(NULL, NULL, NULL, 0, 0);
return dest;
}
return memcpy(dest, src, count * sizeof(wchar_t));
memcpy_s(dest, size * sizeof(wchar_t), src, count * sizeof(wchar_t));
return dest;
}
/* ?copy@?$char_traits@_W@std@@SAPA_WPA_WPB_WI@Z */
......@@ -282,14 +264,8 @@ const wchar_t* CDECL MSVCP_char_traits_wchar_find(
wchar_t* CDECL MSVCP_char_traits_wchar__Move_s(wchar_t *dest,
MSVCP_size_t size, const wchar_t *src, MSVCP_size_t count)
{
if(!dest || !src || size<count) {
if(dest && size)
dest[0] = '\0';
_invalid_parameter(NULL, NULL, NULL, 0, 0);
return dest;
}
return memmove(dest, src, count * sizeof(WCHAR));
memmove_s(dest, size * sizeof(wchar_t), src, count * sizeof(wchar_t));
return dest;
}
/* ?move@?$char_traits@_W@std@@SAPA_WPA_WPB_WI@Z */
......@@ -404,12 +380,8 @@ MSVCP_size_t CDECL MSVCP_char_traits_short_length(const unsigned short *str)
unsigned short * CDECL MSVCP_char_traits_short__Copy_s(unsigned short *dest,
MSVCP_size_t size, const unsigned short *src, MSVCP_size_t count)
{
if(size<count) {
_invalid_parameter(NULL, NULL, NULL, 0, 0);
return dest;
}
return memcpy(dest, src, count * sizeof(unsigned short));
memcpy_s(dest, size * sizeof(unsigned short), src, count * sizeof(unsigned short));
return dest;
}
/* ?copy@?$char_traits@G@std@@SAPAGPAGPBGI@Z */
......@@ -439,12 +411,8 @@ const unsigned short* CDECL MSVCP_char_traits_short_find(
unsigned short* CDECL MSVCP_char_traits_short__Move_s(unsigned short *dest,
MSVCP_size_t size, const unsigned short *src, MSVCP_size_t count)
{
if(size<count) {
_invalid_parameter(NULL, NULL, NULL, 0, 0);
return dest;
}
return memmove(dest, src, count * sizeof(unsigned short));
memmove_s(dest, size * sizeof(unsigned short), src, count * sizeof(unsigned short));
return dest;
}
/* ?move@?$char_traits@G@std@@SAPAGPAGPBGI@Z */
......
......@@ -20,6 +20,7 @@
#include <locale.h>
#include <wctype.h>
#include <float.h>
#include <errno.h>
#include <windef.h>
#include <winbase.h>
......@@ -60,6 +61,7 @@ static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
static _locale_t (__cdecl *p__get_current_locale)(void);
static void (__cdecl *p__free_locale)(_locale_t);
static void (__cdecl *p_free)(void*);
static int * (__cdecl *p_errno)(void);
static void (__cdecl *p_char_assign)(void*, const void*);
static void (__cdecl *p_wchar_assign)(void*, const void*);
......@@ -196,7 +198,8 @@ static BOOL init(void)
p__get_current_locale = (void*)GetProcAddress(msvcr, "_get_current_locale");
p__free_locale = (void*)GetProcAddress(msvcr, "_free_locale");
p_free = (void*)GetProcAddress(msvcr, "free");
if(!p_set_invalid_parameter_handler || !p__get_current_locale || !p__free_locale || !p_free) {
p_errno = (void*)GetProcAddress(msvcr, "_errno");
if(!p_set_invalid_parameter_handler || !p__get_current_locale || !p__free_locale || !p_free || !p_errno) {
win_skip("Error setting tests environment\n");
return FALSE;
}
......@@ -449,7 +452,7 @@ static void test_Copy_s(void)
ok(dest[4] == '#', "dest[4] != '#'\n");
ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
errno = 0xdeadbeef;
*p_errno() = 0xdeadbeef;
dest[0] = '#';
ret = p_Copy_s(dest, 3, src, 4);
ok(ret == dest, "ret != dest\n");
......@@ -457,21 +460,21 @@ static void test_Copy_s(void)
ok(invalid_parameter==1, "invalid_parameter = %d\n",
invalid_parameter);
invalid_parameter = 0;
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
ok(*p_errno() == ERANGE, "errno = %d\n", *p_errno());
errno = 0xdeadbeef;
*p_errno() = 0xdeadbeef;
p_Copy_s(NULL, 32, src, 4);
ok(invalid_parameter==1, "invalid_parameter = %d\n",
invalid_parameter);
invalid_parameter = 0;
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
ok(*p_errno() == EINVAL, "errno = %d\n", *p_errno());
errno = 0xdeadbeef;
*p_errno() = 0xdeadbeef;
p_Copy_s(dest, 32, NULL, 4);
ok(invalid_parameter==1, "invalid_parameter = %d\n",
invalid_parameter);
invalid_parameter = 0;
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
ok(*p_errno() == EINVAL, "errno = %d\n", *p_errno());
}
static void test_wctype(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment