Git Product home page Git Product logo

Comments (7)

philsquared avatar philsquared commented on August 27, 2024

Odd. I'll take a look at that a bit later.

from catch2.

jalfd avatar jalfd commented on August 27, 2024

Browsing the code a bit, the problem seems to be in catch_resultinfo.hpp:47.

expr is an empty string, so the expression m_op( m_expr[0] == '!' ? "!" : "" ) blows up.

from catch2.

philsquared avatar philsquared commented on August 27, 2024

I've not had a chance to try this with MSVC yet (which version, btw?) - but it's very odd for several reasons.

  1. There is no difference between how an INFO in a SECTION is handled - and there are plenty of examples of INFO with a single string that have run happily in MSVC.
  2. expr should not be NULL - it should be "" in this case (see catch_capture:491) - so expr[0] should be '\0' (and that's what I see when I debug from XCode/ gcc).
  3. although expr is a raw char*, it's actually the, just constructed, m_expr that is being tested - which is a std::string. If it made it to there then m_expr[0] should always work.

That said I made a small change to check expr against NULL before checking expr[0]. Let me know if that changes anything. However I suspect that is not actually where your crash is.

If you could confirm which version of MSVC you're using - and any other context that may be relevant, I'll try and reproduce it (assuming my last check-in doesn't fix it).

from catch2.

jalfd avatar jalfd commented on August 27, 2024

expr isn't NULL, it's an empty string, as you expected.

But expr[0] is not valid on an empty string, and so in debug mode, MSVC's extra debug validation will trigger an assert when you try to index into the string. (In release mode, and, I assume, on other compilers, no such assert is in place, and so it happily exceeds the end of the (empty) string, and returns the null character at the end of the buffer. That's relying on undefined behavior though, and so in debug builds, MSVC detects it and triggers an assert.

But it seems that, rather than checking against NULL, you need to check against expr.empty()

from catch2.

philsquared avatar philsquared commented on August 27, 2024

Yes, of course, you are right. If I'd done m_expr.c_str()[0] then it would have forced the null terminator.
So it sounds like my "fix" is really a fix. I'm checking expr against NULL - which is a const char*, rather than m_expr, which is the std::string. Did you try it out?

from catch2.

jalfd avatar jalfd commented on August 27, 2024

I'm without a working compiler for a day or so, so I haven't been able to try it out with your fix yet. But you're right, it looks as if that should solve it. I'll give it a try tomorrow.

from catch2.

jalfd avatar jalfd commented on August 27, 2024

Finally got everything set up on my new laptop so I could try it. It works perfectly, of course. Nicely done. :)

from catch2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.