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 · May be fixed by #248
Open

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

UltimateEvil opened this issue May 30, 2024 · 0 comments · May be fixed by #248

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);
    }
@hirohira9119 hirohira9119 linked a pull request Oct 14, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant