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

When i==arg.size(), arg[i] is out of bounds. #830

Closed
ibc opened this issue Feb 23, 2017 · 5 comments
Closed

When i==arg.size(), arg[i] is out of bounds. #830

ibc opened this issue Feb 23, 2017 · 5 comments

Comments

@ibc
Copy link

ibc commented Feb 23, 2017

https://github.com/philsquared/Catch/blob/master/single_include/catch.hpp#L4435

        void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) {
            for( std::size_t i = 0; i <= arg.size(); ++i ) {
                char c = arg[i];
                if( c == '"' )
                    inQuotes = !inQuotes;
                mode = handleMode( i, c, arg, tokens );
            }
        }

Shouldn't it be for( std::size_t i = 0; i < arg.size(); ++i )?

@philsquared
Copy link
Collaborator

That does look very suspicious. It shouldn't be out of bounds as the character at size() should be a null - although I suspect that the standard allows for the implementation to throw if asked for it (would need to check that).
I suspect that making it < is the right thing to do. The reason I don't sound 100% certain is that there does seem to be handling for null elsewhere and I'd need to check it's not relying on that (and if it is probably change it).
So I'll take a closer look soon.
Have you actually had an issue with it, or did you just spot it manually?

@ibc
Copy link
Author

ibc commented Feb 23, 2017

I just found it by using a code coverage/linter stuff, never experimented an issue related to it.

@horenmar
Copy link
Member

C++03 does not guarantee there being \0 at str[str.size()], in fact I think it does not even guarantee that it is inside the string's bounds.

Granted, I don't think there is an implementation that does not have it there, but it's better to be safe than sorry.

@philsquared
Copy link
Collaborator

Agreed. I'll change it once I've checked for side-effects

@ibc
Copy link
Author

ibc commented Mar 13, 2017

Great.

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

No branches or pull requests

3 participants