* segfault with std::allocator @ 2004-09-03 13:23 Toon Knapen 2004-09-03 13:45 ` Eljay Love-Jensen 0 siblings, 1 reply; 4+ messages in thread From: Toon Knapen @ 2004-09-03 13:23 UTC (permalink / raw) To: gcc-help Following problem segfaults with gcc 3.2.2 inside the deallocate function. AFAICT however, allocation and deallocation of 0 number of objects are allowed ? <code> <code> #include <memory> int main() { std::allocator< int > int_alloc ; int* p = int_alloc.allocate( 0 ) ; int_alloc.deallocate( p, 0 ) ; return 0 ; } </code> ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: segfault with std::allocator 2004-09-03 13:23 segfault with std::allocator Toon Knapen @ 2004-09-03 13:45 ` Eljay Love-Jensen 2004-09-03 13:57 ` Toon Knapen 0 siblings, 1 reply; 4+ messages in thread From: Eljay Love-Jensen @ 2004-09-03 13:45 UTC (permalink / raw) To: Toon Knapen, gcc-help Hi Toon, The deallocate function MUST NOT by passed in a NULL pointer. (According to ISO 14882.) You can fix your code by... #include <memory> int main() { std::allocator< int > int_alloc ; int* p = int_alloc.allocate( 0 ) ; if(p) int_alloc.deallocate( p, 0 ) ; return 0 ; } HTH, --Eljay ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: segfault with std::allocator 2004-09-03 13:45 ` Eljay Love-Jensen @ 2004-09-03 13:57 ` Toon Knapen 2004-09-03 14:34 ` Eljay Love-Jensen 0 siblings, 1 reply; 4+ messages in thread From: Toon Knapen @ 2004-09-03 13:57 UTC (permalink / raw) To: Eljay Love-Jensen; +Cc: gcc-help Eljay Love-Jensen wrote: > > Hi Toon, > > The deallocate function MUST NOT by passed in a NULL pointer. > (According to ISO 14882.) > But 20.4.1.1 par 8 only says "p shall be a pointer obtained from allocate(). n shall equal the value passed as the first argument to the invocation of allocate which returned p". Next as a not is added that it uses '::operator delete' and delete is allowed to be called on a NULL pointer. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: segfault with std::allocator 2004-09-03 13:57 ` Toon Knapen @ 2004-09-03 14:34 ` Eljay Love-Jensen 0 siblings, 0 replies; 4+ messages in thread From: Eljay Love-Jensen @ 2004-09-03 14:34 UTC (permalink / raw) To: Toon Knapen; +Cc: gcc-help Hi Toon, You're not calling delete, your calling int_alloc.deallocate(p, 0); And the deallocate routine (in ISO 14882, table 32 in 20.1.5) specifically says "p must not be null". --Eljay ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-09-03 14:34 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2004-09-03 13:23 segfault with std::allocator Toon Knapen 2004-09-03 13:45 ` Eljay Love-Jensen 2004-09-03 13:57 ` Toon Knapen 2004-09-03 14:34 ` Eljay Love-Jensen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).