#include #include #include #include int times_to_fail = 0; void* allocate(std::size_t n) { /* if (!times_to_fail--) return 0; */ void* ret = std::malloc(n ? n : 1); if (ret) std::memset(ret, 0xbc, n); return ret; } void deallocate(void* p) { if (p) std::free(p); } void* operator new(std::size_t n) throw (std::bad_alloc) { void* ret = allocate(n); if (!ret) throw std::bad_alloc(); return ret; } void* operator new[](std::size_t n) throw (std::bad_alloc) { void* ret = allocate(n); if (!ret) throw std::bad_alloc(); return ret; } void operator delete(void* p) throw() { deallocate(p); } void operator delete[](void* p) throw() { deallocate(p); } void* operator new(std::size_t n, const std::nothrow_t&) throw() { return allocate(n); } void* operator new[](std::size_t n, const std::nothrow_t&) throw() { return allocate(n); } void operator delete(void* p, const std::nothrow_t&) throw() { deallocate(p); } void operator delete[](void* p, const std::nothrow_t&) throw() { deallocate(p); } int main(int argc, char* argv[]) { int iters = 1; if (argc > 1) iters = std::atoi(argv[1]); if (iters < 1) iters = 1; for (int j = 0; j < iters; ++j) { for (int i = 0; i < 100; ++i) { times_to_fail = i; try { std::locale loc1(""); std::locale loc2(loc1, std::locale::classic(), std::locale::numeric); } catch (std::exception&) { } } } return 0; }