incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: [jira] Created: (STDCXX-514) basic_stringbuf<>::str() deallocating external buffer
Date Fri, 10 Aug 2007 17:16:36 GMT
Are you sure this affects 4.1.3? I couldn't reproduce the abort
with it.

Martin


Farid Zaripov (JIRA) wrote:
> basic_stringbuf<>::str() deallocating external buffer
> -----------------------------------------------------
> 
>                  Key: STDCXX-514
>                  URL: https://issues.apache.org/jira/browse/STDCXX-514
>              Project: C++ Standard Library
>           Issue Type: Bug
>           Components: 27. Input/Output
>     Affects Versions: 4.1.3
>          Environment: All
>             Reporter: Farid Zaripov
>             Assignee: Farid Zaripov
>              Fix For: 4.2
> 
> 
> The program below aborts due to deallocating the external buffer extbuf.
> 
> test.cpp:
> ------------------
> #include <sstream>  // for stringbuf
> #include <memory>   // for allocator
> 
> #include <cassert>  // for assert()
> 
> struct MyAlloc : std::allocator <char>
> {
>     static char      __buf [512];
>     static size_type __used_n;
> 
>     pointer allocate (size_type __n, std::allocator<void>::const_pointer = 0) {
>         assert (!__used_n);
> 	assert (sizeof (__buf) >= __n * sizeof (value_type));
>         __used_n = __n;
>         return __buf;
>     }
> 
>     void deallocate (pointer __p, size_type __n)
>     {
>         if (__p) {
>             assert (__buf == __p);
>             assert (__used_n == __n);
> 	    __used_n = 0;
>         }
>     }
> };
> 
> MyAlloc::size_type MyAlloc::__used_n = 0;
> char MyAlloc::__buf [512];
> 
> int main ()
> {
>     char extbuf [3];
>     std::basic_stringbuf <char, std::char_traits <char>, MyAlloc> sbuf;
> 
>     sbuf.pubsetbuf (extbuf, sizeof (extbuf));
>     
>     // stdcxx extension used: basic_stringbuf::str (const char*, size_t)
>     sbuf.str ("abcdef", 6);
> 
>     return 0;
> }
> ------------------
> 
> The test output:
> ------------------
> test: test.cpp:21: void MyAlloc::deallocate(char*, unsigned int): Assertion `__buf ==
__p' failed.
> Aborted
> ------------------
> 
> 


Mime
View raw message