aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDhruv Matani <dhruvbird@gmx.net>2004-03-24 21:40:01 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2004-03-24 21:40:01 +0000
commit58c959212f4871518e4d0d5af8555759cd0cf7a9 (patch)
tree0d0ec11fccc6f462f017f07a58957ab4728af127
parent8367b9c1e9097b487ce56448daec7dfbcc1f09cf (diff)
downloadgcc-58c959212f4871518e4d0d5af8555759cd0cf7a9.zip
gcc-58c959212f4871518e4d0d5af8555759cd0cf7a9.tar.gz
gcc-58c959212f4871518e4d0d5af8555759cd0cf7a9.tar.bz2
malloc_allocator.h: Fixed the construct function to call global placement new instead of assignment.
2004-03-24 Dhruv Matani <dhruvbird@gmx.net> * ext/malloc_allocator.h: Fixed the construct function to call global placement new instead of assignment. Added a check after the return from malloc to check whether returned pointer is NULL, and if so, throw std::bad_alloc(). * ext/debug_allocator.h: Added a check in the deallocate function to check whether the user has passed a NULL pointer or not. From-SVN: r79934
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/ext/debug_allocator.h4
-rw-r--r--libstdc++-v3/include/ext/malloc_allocator.h9
3 files changed, 19 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 77ca7ea..0ab5641 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2004-03-24 Dhruv Matani <dhruvbird@gmx.net>
+
+ * ext/malloc_allocator.h: Fixed the construct function to call
+ global placement new instead of assignment. Added a check after
+ the return from malloc to check whether returned pointer is NULL,
+ and if so, throw std::bad_alloc().
+ * ext/debug_allocator.h: Added a check in the deallocate function
+ to check whether the user has passed a NULL pointer or not.
+
2004-03-24 Benjamin Kosnik <bkoz@redhat.com>
* docs/html/20_util/allocator.html: Add bitmap_allocator links.
diff --git a/libstdc++-v3/include/ext/debug_allocator.h b/libstdc++-v3/include/ext/debug_allocator.h
index eb87680..7ea6fb4 100644
--- a/libstdc++-v3/include/ext/debug_allocator.h
+++ b/libstdc++-v3/include/ext/debug_allocator.h
@@ -108,7 +108,9 @@ namespace __gnu_cxx
void
deallocate(pointer __p, size_type __n)
{
- pointer __real_p = __p - _M_extra;
+ if (!__p)
+ abort();
+ pointer __real_p = __p - _M_extra;
if (*reinterpret_cast<size_type*>(__real_p) != __n)
abort();
_M_allocator.deallocate(__real_p, __n + _M_extra);
diff --git a/libstdc++-v3/include/ext/malloc_allocator.h b/libstdc++-v3/include/ext/malloc_allocator.h
index dc6ae4f..938380c 100644
--- a/libstdc++-v3/include/ext/malloc_allocator.h
+++ b/libstdc++-v3/include/ext/malloc_allocator.h
@@ -78,7 +78,12 @@ namespace __gnu_cxx
// about what the return value is when __n == 0.
pointer
allocate(size_type __n, const void* = 0)
- { return static_cast<_Tp*>(malloc(__n * sizeof(_Tp))); }
+ {
+ pointer __ret = static_cast<_Tp*>(malloc(__n * sizeof(_Tp)));
+ if (!__ret)
+ throw std::bad_alloc();
+ return __ret;
+ }
// __p is not permitted to be a null pointer.
void
@@ -93,7 +98,7 @@ namespace __gnu_cxx
// 402. wrong new expression in [some_] allocator::construct
void
construct(pointer __p, const _Tp& __val)
- { *__p = __val; }
+ { ::new(__p) value_type(__val); }
void
destroy(pointer __p) { __p->~_Tp(); }