Commit ff5d176c authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcp90: Always throw bad_alloc exception in operator_new on allocation failure.

parent 3a86f0a6
...@@ -3913,10 +3913,6 @@ void __thiscall basic_stringbuf_char__Init(basic_stringbuf_char *this, const cha ...@@ -3913,10 +3913,6 @@ void __thiscall basic_stringbuf_char__Init(basic_stringbuf_char *this, const cha
if(count && str) { if(count && str) {
char *buf = operator_new(count); char *buf = operator_new(count);
if(!buf) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
memcpy(buf, str, count); memcpy(buf, str, count);
this->seekhigh = buf + count; this->seekhigh = buf + count;
...@@ -4051,10 +4047,6 @@ int __thiscall basic_stringbuf_char_overflow(basic_stringbuf_char *this, int met ...@@ -4051,10 +4047,6 @@ int __thiscall basic_stringbuf_char_overflow(basic_stringbuf_char *this, int met
size = oldsize|0xf; size = oldsize|0xf;
size += size/2; size += size/2;
buf = operator_new(size); buf = operator_new(size);
if(!buf) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
if(!oldsize) { if(!oldsize) {
this->seekhigh = buf; this->seekhigh = buf;
...@@ -4290,10 +4282,6 @@ void __thiscall basic_stringbuf_wchar__Init(basic_stringbuf_wchar *this, const w ...@@ -4290,10 +4282,6 @@ void __thiscall basic_stringbuf_wchar__Init(basic_stringbuf_wchar *this, const w
if(count && str) { if(count && str) {
wchar_t *buf = operator_new(count*sizeof(wchar_t)); wchar_t *buf = operator_new(count*sizeof(wchar_t));
if(!buf) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
memcpy(buf, str, count*sizeof(wchar_t)); memcpy(buf, str, count*sizeof(wchar_t));
this->seekhigh = buf + count; this->seekhigh = buf + count;
...@@ -4464,10 +4452,6 @@ unsigned short __thiscall basic_stringbuf_wchar_overflow(basic_stringbuf_wchar * ...@@ -4464,10 +4452,6 @@ unsigned short __thiscall basic_stringbuf_wchar_overflow(basic_stringbuf_wchar *
size = oldsize|0xf; size = oldsize|0xf;
size += size/2; size += size/2;
buf = operator_new(size*sizeof(wchar_t)); buf = operator_new(size*sizeof(wchar_t));
if(!buf) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
if(!oldsize) { if(!oldsize) {
this->seekhigh = buf; this->seekhigh = buf;
......
...@@ -58,24 +58,36 @@ DEFINE_VTBL_WRAPPER(56); ...@@ -58,24 +58,36 @@ DEFINE_VTBL_WRAPPER(56);
/* ?_Fpz@std@@3_JB */ /* ?_Fpz@std@@3_JB */
const __int64 std_Fpz = 0; const __int64 std_Fpz = 0;
void* (__cdecl *operator_new)(size_t); static void* (__cdecl *MSVCRT_operator_new)(size_t);
void (__cdecl *operator_delete)(void*); static void (__cdecl *MSVCRT_operator_delete)(void*);
void* (__cdecl *MSVCRT_set_new_handler)(void*); void* (__cdecl *MSVCRT_set_new_handler)(void*);
void* __cdecl operator_new(size_t size)
{
void *ret = MSVCRT_operator_new(size);
if (!ret) throw_exception(EXCEPTION_BAD_ALLOC, "bad allocation");
return ret;
}
void __cdecl operator_delete(void *mem)
{
MSVCRT_operator_delete(mem);
}
static void init_cxx_funcs(void) static void init_cxx_funcs(void)
{ {
HMODULE hmod = GetModuleHandleA("msvcrt.dll"); HMODULE hmod = GetModuleHandleA("msvcrt.dll");
if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */ if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
{ {
operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z"); MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z"); MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z"); MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
} }
else else
{ {
operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z"); MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z"); MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z"); MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
} }
} }
......
...@@ -32,8 +32,8 @@ void __cdecl _invalid_parameter(const wchar_t*, const wchar_t*, ...@@ -32,8 +32,8 @@ void __cdecl _invalid_parameter(const wchar_t*, const wchar_t*,
const wchar_t*, unsigned int, uintptr_t); const wchar_t*, unsigned int, uintptr_t);
BOOL __cdecl __uncaught_exception(void); BOOL __cdecl __uncaught_exception(void);
extern void* (__cdecl *operator_new)(size_t); void* __cdecl operator_new(size_t);
extern void (__cdecl *operator_delete)(void*); void __cdecl operator_delete(void*);
/* basic_string<char, char_traits<char>, allocator<char>> */ /* basic_string<char, char_traits<char>, allocator<char>> */
typedef struct typedef struct
......
...@@ -4331,10 +4331,6 @@ void __thiscall basic_stringbuf_char__Init(basic_stringbuf_char *this, const cha ...@@ -4331,10 +4331,6 @@ void __thiscall basic_stringbuf_char__Init(basic_stringbuf_char *this, const cha
if(count && str) { if(count && str) {
char *buf = operator_new(count); char *buf = operator_new(count);
if(!buf) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
memcpy(buf, str, count); memcpy(buf, str, count);
this->seekhigh = buf + count; this->seekhigh = buf + count;
...@@ -4469,10 +4465,6 @@ int __thiscall basic_stringbuf_char_overflow(basic_stringbuf_char *this, int met ...@@ -4469,10 +4465,6 @@ int __thiscall basic_stringbuf_char_overflow(basic_stringbuf_char *this, int met
size = oldsize|0xf; size = oldsize|0xf;
size += size/2; size += size/2;
buf = operator_new(size); buf = operator_new(size);
if(!buf) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
if(!oldsize) { if(!oldsize) {
this->seekhigh = buf; this->seekhigh = buf;
...@@ -4708,10 +4700,6 @@ void __thiscall basic_stringbuf_wchar__Init(basic_stringbuf_wchar *this, const w ...@@ -4708,10 +4700,6 @@ void __thiscall basic_stringbuf_wchar__Init(basic_stringbuf_wchar *this, const w
if(count && str) { if(count && str) {
wchar_t *buf = operator_new(count*sizeof(wchar_t)); wchar_t *buf = operator_new(count*sizeof(wchar_t));
if(!buf) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
memcpy(buf, str, count*sizeof(wchar_t)); memcpy(buf, str, count*sizeof(wchar_t));
this->seekhigh = buf + count; this->seekhigh = buf + count;
...@@ -4882,10 +4870,6 @@ unsigned short __thiscall basic_stringbuf_wchar_overflow(basic_stringbuf_wchar * ...@@ -4882,10 +4870,6 @@ unsigned short __thiscall basic_stringbuf_wchar_overflow(basic_stringbuf_wchar *
size = oldsize|0xf; size = oldsize|0xf;
size += size/2; size += size/2;
buf = operator_new(size*sizeof(wchar_t)); buf = operator_new(size*sizeof(wchar_t));
if(!buf) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
if(!oldsize) { if(!oldsize) {
this->seekhigh = buf; this->seekhigh = buf;
......
...@@ -263,11 +263,6 @@ DEFINE_THISCALL_WRAPPER(mutex_ctor, 4) ...@@ -263,11 +263,6 @@ DEFINE_THISCALL_WRAPPER(mutex_ctor, 4)
mutex* __thiscall mutex_ctor(mutex *this) mutex* __thiscall mutex_ctor(mutex *this)
{ {
CRITICAL_SECTION *cs = operator_new(sizeof(*cs)); CRITICAL_SECTION *cs = operator_new(sizeof(*cs));
if(!cs) {
ERR("Out of memory\n");
throw_exception(EXCEPTION_BAD_ALLOC, NULL);
}
InitializeCriticalSection(cs); InitializeCriticalSection(cs);
cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section"); cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section");
this->mutex = cs; this->mutex = cs;
......
...@@ -41,13 +41,8 @@ void __cdecl _invalid_parameter_noinfo(void); ...@@ -41,13 +41,8 @@ void __cdecl _invalid_parameter_noinfo(void);
BOOL __cdecl __uncaught_exception(void); BOOL __cdecl __uncaught_exception(void);
int __cdecl _callnewh(size_t); int __cdecl _callnewh(size_t);
#if _MSVCP_VER >= 140
void* __cdecl operator_new(size_t); void* __cdecl operator_new(size_t);
void __cdecl operator_delete(void*); void __cdecl operator_delete(void*);
#else
extern void* (__cdecl *operator_new)(size_t);
extern void (__cdecl *operator_delete)(void*);
#endif
extern void* (__cdecl *MSVCRT_set_new_handler)(void*); extern void* (__cdecl *MSVCRT_set_new_handler)(void*);
#if _MSVCP_VER >= 110 #if _MSVCP_VER >= 110
......
...@@ -109,8 +109,22 @@ void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const ...@@ -109,8 +109,22 @@ void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const
_invalid_parameter_noinfo(); _invalid_parameter_noinfo();
} }
#else #else
void* (__cdecl *operator_new)(size_t); static void* (__cdecl *MSVCRT_operator_new)(size_t);
void (__cdecl *operator_delete)(void*); static void (__cdecl *MSVCRT_operator_delete)(void*);
void* __cdecl operator_new(size_t size)
{
void *ret = MSVCRT_operator_new(size);
#if _MSVCP_VER < 80
if (!ret) throw_exception(EXCEPTION_BAD_ALLOC, "bad allocation");
#endif
return ret;
}
void __cdecl operator_delete(void *mem)
{
MSVCRT_operator_delete(mem);
}
#endif #endif
static void init_cxx_funcs(void) static void init_cxx_funcs(void)
...@@ -130,14 +144,14 @@ static void init_cxx_funcs(void) ...@@ -130,14 +144,14 @@ static void init_cxx_funcs(void)
#else #else
if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */ if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
{ {
operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z"); MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z"); MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z"); MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
} }
else else
{ {
operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z"); MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z"); MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z"); MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
} }
#endif #endif
......
...@@ -1648,10 +1648,6 @@ _Yarn_char* __thiscall _Yarn_char_op_assign_cstr(_Yarn_char *this, const char *s ...@@ -1648,10 +1648,6 @@ _Yarn_char* __thiscall _Yarn_char_op_assign_cstr(_Yarn_char *this, const char *s
size_t len = strlen(str); size_t len = strlen(str);
this->str = operator_new((len+1)*sizeof(char)); this->str = operator_new((len+1)*sizeof(char));
if(!this->str) {
ERR("out of memory\n");
return NULL;
}
memcpy(this->str, str, (len+1)*sizeof(char)); memcpy(this->str, str, (len+1)*sizeof(char));
} }
} }
...@@ -1768,10 +1764,6 @@ _Yarn_wchar* __thiscall _Yarn_wchar_op_assign_cstr(_Yarn_wchar *this, const wcha ...@@ -1768,10 +1764,6 @@ _Yarn_wchar* __thiscall _Yarn_wchar_op_assign_cstr(_Yarn_wchar *this, const wcha
size_t len = wcslen(str); size_t len = wcslen(str);
this->str = operator_new((len+1)*sizeof(wchar_t)); this->str = operator_new((len+1)*sizeof(wchar_t));
if(!this->str) {
ERR("out of memory\n");
return NULL;
}
memcpy(this->str, str, (len+1)*sizeof(wchar_t)); memcpy(this->str, str, (len+1)*sizeof(wchar_t));
} }
} }
......
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