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