Commit dea455b3640db0798cc5ef0d2322bb64e099fd7a

Authored by Grzegorz Jabłoński
1 parent fe908fbd

Improved max size checking

examples11/04-vectortmpl/vector.h
@@ -109,7 +109,7 @@ public: @@ -109,7 +109,7 @@ public:
109 new (data + size) C(s); 109 new (data + size) C(s);
110 ++size; 110 ++size;
111 } else { 111 } else {
112 - if (cap > std::numeric_limits<decltype(size)>::max() / 2) 112 + if (cap > std::numeric_limits<decltype(size)>::max() / (2*sizeof(C)))
113 throw bad_alloc(); 113 throw bad_alloc();
114 unsigned int newcap = (cap == 0) ? 1 : 2 * cap; 114 unsigned int newcap = (cap == 0) ? 1 : 2 * cap;
115 C *newdata; 115 C *newdata;