incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Pevtsov" <Ant...@moscow.vdiweb.com>
Subject 21.string.replace length_error (win32, msvc-7.1)
Date Mon, 24 Apr 2006 15:13:14 GMT
The following code fails with access violation (segmentation fault on
Linux) error on Win32, MSVC-7.1 (Suse Linux, gcc 4.0.2)

#include <iostream>
#include <string>
#include <stdexcept>

static char long_string [4096] = {'a'};

int main (void)
{
    try 
    {
        std::string s (long_string, 4095);
        s.replace (0, 1, "a", s.max_size () + 1);

        std::cout << "Expect length error, got nothing" << '\n';
    }
    catch (std::length_error& e)
    {
        std::cout << "Got expected length error" << '\n';
    }

    return 0;
}


I suspect a bug in replace implementation, string.cc line 327:
The check 

__size0 - __xlen <= max_size () - __n2

is not enough in this case.


Could you take a look when you have a chance, please?


Thanks,
Anton Pevtsov

Mime
View raw message