libstdc++: Adjust overflow prevention to operator>>
authorJonathan Wakely <jwakely@redhat.com>
Thu, 6 Aug 2020 15:16:33 +0000 (16:16 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 6 Aug 2020 17:26:45 +0000 (18:26 +0100)
commit6251ea15f55ec57d6325c2e37e88b22315aba658
tree0f44c42a6daea85c951e58e781fb2a6c7f4bf37b
parent9c376d1c166e7c8b10bba6f1675d2471ffe8447f
libstdc++: Adjust overflow prevention to operator>>

This adjusts the overflow prevention added to operator>> so that we can
distinguish "unknown size" from "zero size", and avoid writing anything
at all in to zero sized buffers.

This also removes the incorrect comment saying extraction stops at a
null byte.

libstdc++-v3/ChangeLog:

* include/std/istream (operator>>(istream&, char*)): Add
attributes to get warnings for pointers that are null or known
to point to the end of a buffer. Request upper bound from
__builtin_object_size check and handle zero-sized buffer case.
(operator>>(istream&, signed char))
(operator>>(istream&, unsigned char*)): Add attributes.
* testsuite/27_io/basic_istream/extractors_character/char/overflow.cc:
Check extracting into the middle of a buffer.
* testsuite/27_io/basic_istream/extractors_character/wchar_t/overflow.cc: New test.
libstdc++-v3/include/std/istream
libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/overflow.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/overflow.cc [new file with mode: 0644]