public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61735] New: basic_string bug when type_size is char.
@ 2014-07-07 13:45 gkourtis at freemail dot gr
2014-07-07 16:33 ` [Bug libstdc++/61735] " redi at gcc dot gnu.org
2024-03-17 0:45 ` [Bug libstdc++/61735] pre-C++11 basic_string bug when type_size is char (-D_GLIBCXX_USE_CXX11_ABI=0) pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: gkourtis at freemail dot gr @ 2014-07-07 13:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61735
Bug ID: 61735
Summary: basic_string bug when type_size is char.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gkourtis at freemail dot gr
I use g++ and I have defined a custom allocator where the size_type is byte. I
am using it with basic_string to create custom strings.
The "basic_string.tcc" code behaves erroneously because in the code of
_S_create(size_type __capacity, size_type __old_capacity, const _Alloc&
__alloc)
the code checks for
const size_type __extra = __pagesize - __adj_size % __pagesize;
But all the arithmetic are byte arithmetic and so __pagesize that should have a
value 4096, becomes 0 (because 4096 is a multiple of 256 and bigger of 256) and
we have a "division by 0" exception (the code hangs).
I used the subsequent code to eliminate the unwanted effect:
#include <limits>
#define __pagesize_def 4096
{
if(std::numeric_limits<size_type>::max()>=__pagesize_def)
{ const size_type __extra = __pagesize - __adj_size % __pagesize; __capacity +=
__extra / sizeof(_CharT);
}
A little bit of discussion at:
http://stackoverflow.com/questions/24595837/bug-in-stdbasic-string-in-special-case-of-allocator
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/61735] basic_string bug when type_size is char.
2014-07-07 13:45 [Bug c++/61735] New: basic_string bug when type_size is char gkourtis at freemail dot gr
@ 2014-07-07 16:33 ` redi at gcc dot gnu.org
2024-03-17 0:45 ` [Bug libstdc++/61735] pre-C++11 basic_string bug when type_size is char (-D_GLIBCXX_USE_CXX11_ABI=0) pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-07 16:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61735
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |NEW
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
#include <string>
template<typename T>
struct tiny_allocator : std::allocator<T>
{
template<typename U> struct rebind { typedef tiny_allocator<U> other; };
typedef unsigned char size_type;
static size_type max_size() { return 255; }
};
int main()
{
std::basic_string<char, std::char_traits<char>, tiny_allocator<char> > s;
s += 'a';
}
ubsan notices the error:
/home/jwakely/gcc/4.x/include/c++/4.10.0/bits/basic_string.tcc:597:54: runtime
error: division by zero
Floating point exception (core dumped)
The fix might be as simple as changing the type of __pagesize to unsigned,
although I expect there are other overflow issues lurking for an 8-bit
size_type.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/61735] pre-C++11 basic_string bug when type_size is char (-D_GLIBCXX_USE_CXX11_ABI=0)
2014-07-07 13:45 [Bug c++/61735] New: basic_string bug when type_size is char gkourtis at freemail dot gr
2014-07-07 16:33 ` [Bug libstdc++/61735] " redi at gcc dot gnu.org
@ 2024-03-17 0:45 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-17 0:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61735
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|basic_string bug when |pre-C++11 basic_string bug
|type_size is char. |when type_size is char
| |(-D_GLIBCXX_USE_CXX11_ABI=0
| |)
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I will note that the (default) newer basic_string that was included in GCC 5+
does not have this issue but the pre-c++ ABI basic_string still has this issue.
That is you need -D_GLIBCXX_USE_CXX11_ABI=0 to hit the issue now.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-17 0:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-07 13:45 [Bug c++/61735] New: basic_string bug when type_size is char gkourtis at freemail dot gr
2014-07-07 16:33 ` [Bug libstdc++/61735] " redi at gcc dot gnu.org
2024-03-17 0:45 ` [Bug libstdc++/61735] pre-C++11 basic_string bug when type_size is char (-D_GLIBCXX_USE_CXX11_ABI=0) pinskia at gcc dot gnu.org
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).