[PATCH] Ensure std::getline always 0-terminates string.

Reimar Döffinger via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 12 12:37:22 PST 2017


On Thu, Nov 09, 2017 at 05:37:32PM -0800, Volodymyr Sapsai wrote:
> On Nov 9, 2017, at 12:13, Reimar Döffinger <Reimar.Doeffinger at gmx.de> wrote:
> > 
> > Hello!
> > 
> > On Wed, Nov 08, 2017 at 12:36:00PM -0800, Volodymyr Sapsai wrote:
> >> Thanks for the patch, Reimar. Can you please add tests to ensure this functionality doesn’t regress? As null character is required by the standard (27.7.2.3p21), a good starting point seems to be
> >> test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp
> >> test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp
> > 
> > New patch attached, though I went the lazy way of just adding one case.
> > Not sure that's "good enough" - in principle I think it should be.
> I think it makes sense to cover wchar_t as well. And I think it would be useful to test the case with specified delimiter too. Most likely implementation should be reused for the case with explicit delimiter and default new line delimiter. But I prefer not to rely on this assumption and test explicitly.

Well, it was rather trivial to do anyway, so done.

> > More tricky would be to add a test for the _LIBCPP_NO_EXCEPTIONS case,
> > is there any code testing that at all?
> According to tests, exceptions are tested in various ways. Let me find how to configure the build to run tests in these modes.

There aren't many references to that mode, and I am not sure
running in a separate mode would make for a good test anyway.
Maybe not how it should done, but for now I added a separate file
that just defines _LIBCPP_NO_EXCEPTIONS before the includes.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Ensure-std-istream-getline-always-0-terminates-strin.patch
Type: text/x-diff
Size: 6682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171112/07d418e4/attachment-0001.patch>


More information about the cfe-commits mailing list