https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124650

            Bug ID: 124650
           Summary: GCC double free sigsev segmentation fault std::string
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following program results in seg fault: https://godbolt.org/z/nMxbr6qWM
```
#include <iostream>

class MyClass {
public:
    std::string shrinkAndCopy(std::string &stream) {
        size_t pos = 5;
        return stream = stream.substr(pos);
    }

    void modify(std::string &stream) {
        std::string key = this->shrinkAndCopy(stream);
        throw std::runtime_error("boom");
    }

    void run() {
        std::string stream = "aaa[ERASE]aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";  // at
least 40 chars
        size_t pos = 3;
        size_t end = 10;
        stream.erase(pos, end - pos);
        this->modify(stream);
    }
};

int main(void) {
    try {
        MyClass myClass;
        myClass.run();
        return 0;
    }
    catch (...) {
        exit(1);
    }
}
```

Reply via email to