Skip to content

Commit 06ef752

Browse files
committed
[libc++] Implement LWG3464(istream::gcount() can overflow)
Implement LWG3464 https://wg21.link/LWG3464 Reviewed By: #libc, Mordante, philnik Differential Revision: https://reviews.llvm.org/D158749
1 parent 36998cc commit 06ef752

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"`3432 <https://wg21.link/LWG3432>`__","Missing requirement for ``comparison_category``","November 2020","|Complete|","16.0","|spaceship|"
1111
"`3447 <https://wg21.link/LWG3447>`__","Deduction guides for ``take_view`` and ``drop_view`` have different constraints","November 2020","|Complete|","14.0","|ranges|"
1212
"`3450 <https://wg21.link/LWG3450>`__","The const overloads of ``take_while_view::begin/end`` are underconstrained","November 2020","|Complete|","16.0","|ranges|"
13-
"`3464 <https://wg21.link/LWG3464>`__","``istream::gcount()`` can overflow","November 2020","",""
13+
"`3464 <https://wg21.link/LWG3464>`__","``istream::gcount()`` can overflow","November 2020","|Complete|","18.0"
1414
"`2731 <https://wg21.link/LWG2731>`__","Existence of ``lock_guard<MutexTypes...>::mutex_type`` typedef unclear","November 2020","|Complete|","5.0"
1515
"`2743 <https://wg21.link/LWG2743>`__","P0083R3 ``node_handle`` private members missing ""exposition only"" comment","November 2020","|Nothing To Do|",""
1616
"`2820 <https://wg21.link/LWG2820>`__","Clarify ``<cstdint>`` macros","November 2020","|Nothing To Do|",""

libcxx/include/istream

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ class _LIBCPP_TEMPLATE_VIS basic_istream
185185
: virtual public basic_ios<_CharT, _Traits>
186186
{
187187
streamsize __gc_;
188+
189+
_LIBCPP_HIDE_FROM_ABI void __inc_gcount() {
190+
if (__gc_ < numeric_limits<streamsize>::max())
191+
++__gc_;
192+
}
188193
public:
189194
// types (inherited from basic_ios (27.5.4)):
190195
typedef _CharT char_type;
@@ -714,7 +719,7 @@ basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_typ
714719
__sb->sputc(traits_type::to_char_type(__i)),
715720
traits_type::eof()))
716721
break;
717-
++__gc_;
722+
__inc_gcount();
718723
this->rdbuf()->sbumpc();
719724
}
720725
if (__gc_ == 0)
@@ -806,7 +811,7 @@ basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __
806811
if (traits_type::eq(__ch, __dlm))
807812
break;
808813
*__s++ = __ch;
809-
++__gc_;
814+
__inc_gcount();
810815
this->rdbuf()->sbumpc();
811816
}
812817
if (__gc_ == 0)
@@ -867,7 +872,7 @@ basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __s
867872
break;
868873
if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
869874
break;
870-
++__gc_;
875+
__inc_gcount();
871876
this->rdbuf()->sbumpc();
872877
}
873878
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
@@ -910,7 +915,7 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ
910915
if (traits_type::eq(__ch, __dlm))
911916
{
912917
this->rdbuf()->sbumpc();
913-
++__gc_;
918+
__inc_gcount();
914919
break;
915920
}
916921
if (__gc_ >= __n-1)
@@ -920,7 +925,7 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ
920925
}
921926
*__s++ = __ch;
922927
this->rdbuf()->sbumpc();
923-
++__gc_;
928+
__inc_gcount();
924929
}
925930
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
926931
}
@@ -970,7 +975,7 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
970975
__state |= ios_base::eofbit;
971976
break;
972977
}
973-
++__gc_;
978+
__inc_gcount();
974979
if (traits_type::eq_int_type(__i, __dlm))
975980
break;
976981
}
@@ -985,7 +990,7 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
985990
__state |= ios_base::eofbit;
986991
break;
987992
}
988-
++__gc_;
993+
__inc_gcount();
989994
if (traits_type::eq_int_type(__i, __dlm))
990995
break;
991996
}

0 commit comments

Comments
 (0)