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

Issues when using non null-terminated string views. #232

Open
UltimateEvil opened this issue May 30, 2024 · 0 comments
Open

Issues when using non null-terminated string views. #232

UltimateEvil opened this issue May 30, 2024 · 0 comments

Comments

@UltimateEvil
Copy link

I, for whichever reson, have a string which contains a CSV as a substring.

Currently when calling parse("1,2,3,4"sv.substr(2),format) the following code is executed

CSVReader parse(csv::string_view in, CSVFormat format) {
        std::stringstream stream(in.data());
        return CSVReader(stream, format);
    }

This will read memory outside the string view due to the following constructor bing invoked:

explicit basic_stringstream
    ( std::basic_string<CharT, Traits, Allocator>&& str,
      std::ios_base::openmode mode =
          std::ios_base::in | std::ios_base::out);

In c++ 26 the following is fine

CSVReader parse(csv::string_view in, CSVFormat format) {
        std::stringstream stream(in);
        return CSVReader(stream, format);
    }

Untill then, please document this behaviour or change it so the call is instead using a correctly constructed string

CSVReader parse(csv::string_view in, CSVFormat format) {
        std::stringstream stream(std::string{in});
        return CSVReader(stream, format);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant