Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when using ValuesGenerator<bool> #1692

Closed
moha-gh opened this issue Jul 17, 2019 · 2 comments
Closed

Segfault when using ValuesGenerator<bool> #1692

moha-gh opened this issue Jul 17, 2019 · 2 comments
Labels

Comments

@moha-gh
Copy link
Contributor

moha-gh commented Jul 17, 2019

Describe the bug

We are currently migrating from v2.5.0 to v2.9.1 and have experienced segfaults in various tests. AddressSanitizer reports stack-use-after-return for those. It turns out that the root cause seems to be usage of ValuesGenerator<bool> in the affected tests.

Expected behavior

  • No segfaults / ASAN findings.

Reproduction steps

The following minimal example reproduces the issue 100% locally:

  • SEGFAULT when executing binary compiled with GCC
  • stack-use-after-return reported by ASAN when analysing binary compiled with clang

When compiling with clang (without ASAN) and running the test, the crash does not occur.

TEST_CASE("Bool Generator Segfault")
{
    // Segfaults
    auto state = GENERATE(values<bool>({ true, false }));
    // Those two do not ...
    // auto state = GENERATE(true, false);
    // auto state = GENERATE(as<bool> {}, true, false);
    SECTION("foo bar")
    {
        INFO(state);
        SUCCEED();
    }
}

Using the alternative syntax (which, if I understood the docs correctly leads to two separate instances of ValueGenerator<T> being concatenated instead of a single ValuesGenerator<T>) does not segfault and triggers no ASAN findings.

Platform information:

  • OS: Linux
  • Compiler+version: GCC 7.4.0 / clang 8.0.0
  • Catch version: v2.9.1

Additional context

n/a

@moha-gh
Copy link
Contributor Author

moha-gh commented Jul 17, 2019

@horenmar
Copy link
Member

At a quick glance, it seems that the std::vector<bool> specialization strikes again. The problem is that the ValuesGenerator<T> internally holds a std::vector<T>, which, for bool, breaks, because std::vector<bool> is a weird type that messes around with proxies to single bits, instead of storing full booleans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants