aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@unitus.it>2003-10-01 16:32:05 +0200
committerPaolo Carlini <paolo@gcc.gnu.org>2003-10-01 14:32:05 +0000
commit52a16d0815a08b0af6fba0c24a87917de17e3ef1 (patch)
treec2f64bee96b9b95b056f79ee6d5328f71cf15499
parentd00eacabf417e4a03b96998bbbffa4d6e2804195 (diff)
downloadgcc-52a16d0815a08b0af6fba0c24a87917de17e3ef1.zip
gcc-52a16d0815a08b0af6fba0c24a87917de17e3ef1.tar.gz
gcc-52a16d0815a08b0af6fba0c24a87917de17e3ef1.tar.bz2
re PR libstdc++/12439 (Problems in time_put::put)
2003-10-01 Paolo Carlini <pcarlini@unitus.it> PR libstdc++/12439 * include/bits/locale_facets.tcc (time_put::put): Deal with the three issues pointed out by the PR. * testsuite/22_locale/time_put/put/char/12439_1.cc: New. * testsuite/22_locale/time_put/put/char/12439_3.cc: New. * testsuite/22_locale/time_put/put/wchar_t/12439_1.cc: New. * testsuite/22_locale/time_put/put/wchar_t/12439_2.cc: New. * testsuite/22_locale/time_put/put/wchar_t/12439_3.cc: New. From-SVN: r71976
-rw-r--r--libstdc++-v3/ChangeLog11
-rw-r--r--libstdc++-v3/include/bits/locale_facets.tcc16
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_put/put/char/12439_1.cc64
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_put/put/char/12439_3.cc62
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_1.cc64
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_2.cc60
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_3.cc62
7 files changed, 329 insertions, 10 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 2c0b50b..4b776c8 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,14 @@
+2003-10-01 Paolo Carlini <pcarlini@unitus.it>
+
+ PR libstdc++/12439
+ * include/bits/locale_facets.tcc (time_put::put): Deal
+ with the three issues pointed out by the PR.
+ * testsuite/22_locale/time_put/put/char/12439_1.cc: New.
+ * testsuite/22_locale/time_put/put/char/12439_3.cc: New.
+ * testsuite/22_locale/time_put/put/wchar_t/12439_1.cc: New.
+ * testsuite/22_locale/time_put/put/wchar_t/12439_2.cc: New.
+ * testsuite/22_locale/time_put/put/wchar_t/12439_3.cc: New.
+
2003-09-30 Paolo Carlini <pcarlini@unitus.it>
* include/bits/stl_algo.h: Minor cosmetic reformattings.
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 4c81603..62127b9 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -2000,21 +2000,20 @@ namespace std
template<typename _CharT, typename _OutIter>
_OutIter
time_put<_CharT, _OutIter>::
- put(iter_type __s, ios_base& __io, char_type, const tm* __tm,
+ put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
const _CharT* __beg, const _CharT* __end) const
{
locale __loc = __io.getloc();
ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
while (__beg != __end)
{
- char __c = __ctype.narrow(*__beg, 0);
+ const _CharT* __tmp = __beg;
++__beg;
- if (__c == '%')
+ if (__ctype.narrow(*__tmp, 0) == '%' && __beg != __end)
{
char __format;
char __mod = 0;
- size_t __len = 1;
- __c = __ctype.narrow(*__beg, 0);
+ const char __c = __ctype.narrow(*__beg, 0);
++__beg;
if (__c == 'E' || __c == 'O')
{
@@ -2024,13 +2023,10 @@ namespace std
}
else
__format = __c;
- __s = this->do_put(__s, __io, _CharT(), __tm, __format, __mod);
+ __s = this->do_put(__s, __io, __fill, __tm, __format, __mod);
}
else
- {
- *__s = __c;
- ++__s;
- }
+ *__s++ = *__tmp;
}
return __s;
}
diff --git a/libstdc++-v3/testsuite/22_locale/time_put/put/char/12439_1.cc b/libstdc++-v3/testsuite/22_locale/time_put/put/char/12439_1.cc
new file mode 100644
index 0000000..bc3bb86
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_put/put/char/12439_1.cc
@@ -0,0 +1,64 @@
+// Copyright (C) 2003 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 22.2.5.3.1 time_put members
+
+#include <locale>
+#include <sstream>
+#include <ctime>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+class TP : public std::time_put<char>
+{
+public:
+ mutable std::string fill_chars;
+
+protected:
+ iter_type do_put(iter_type s, std::ios_base&, char_type fill,
+ const std::tm* t, char format, char modifier) const
+ {
+ fill_chars.push_back(fill);
+ return s;
+ }
+};
+
+// libstdc++/12439
+// time_put::put doesn't pass fill character to do_put
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ ostringstream stream;
+ time_t tt = time(NULL);
+
+ const char* fmt = "%c";
+
+ TP tp;
+ tp.put(TP::iter_type(stream), stream, 'W', localtime(&tt),
+ fmt, fmt + strlen(fmt));
+ VERIFY( !tp.fill_chars.empty() );
+ VERIFY( tp.fill_chars[tp.fill_chars.length() - 1] == 'W' );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_put/put/char/12439_3.cc b/libstdc++-v3/testsuite/22_locale/time_put/put/char/12439_3.cc
new file mode 100644
index 0000000..c1d0167
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_put/put/char/12439_3.cc
@@ -0,0 +1,62 @@
+// Copyright (C) 2003 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 22.2.5.3.1 time_put members
+
+#include <locale>
+#include <sstream>
+#include <ctime>
+#include <testsuite_hooks.h>
+
+class TP : public std::time_put<char>
+{
+public:
+ mutable std::string format_chars;
+
+protected:
+ iter_type do_put(iter_type s, std::ios_base&, char_type fill,
+ const std::tm* t, char format, char modifier) const
+ {
+ format_chars.push_back(format);
+ return s;
+ }
+};
+
+// libstdc++/12439
+// time_put::put reads past end of format string
+void test03()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ ostringstream stream;
+ time_t tt = time(NULL);
+
+ const char* fmt = "%c";
+
+ TP tp;
+ tp.put(TP::iter_type(stream), stream, stream.fill(), localtime(&tt),
+ fmt, fmt + 1);
+ VERIFY( tp.format_chars.empty() );
+}
+
+int main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_1.cc b/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_1.cc
new file mode 100644
index 0000000..ce2d0d5
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_1.cc
@@ -0,0 +1,64 @@
+// Copyright (C) 2003 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 22.2.5.3.1 time_put members
+
+#include <locale>
+#include <sstream>
+#include <ctime>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+class TP : public std::time_put<wchar_t>
+{
+public:
+ mutable std::wstring fill_chars;
+
+protected:
+ iter_type do_put(iter_type s, std::ios_base&, char_type fill,
+ const std::tm* t, char format, char modifier) const
+ {
+ fill_chars.push_back(fill);
+ return s;
+ }
+};
+
+// libstdc++/12439
+// time_put::put doesn't pass fill character to do_put
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ wostringstream stream;
+ time_t tt = time(NULL);
+
+ const wchar_t* fmt = L"%c";
+
+ TP tp;
+ tp.put(TP::iter_type(stream), stream, L'W', localtime(&tt),
+ fmt, fmt + wcslen(fmt));
+ VERIFY( !tp.fill_chars.empty() );
+ VERIFY( tp.fill_chars[tp.fill_chars.length() - 1] == L'W' );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_2.cc b/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_2.cc
new file mode 100644
index 0000000..6715cc5
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_2.cc
@@ -0,0 +1,60 @@
+// Copyright (C) 2003 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 22.2.5.3.1 time_put members
+
+#include <locale>
+#include <sstream>
+#include <ctime>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+// libstdc++/12439
+// time_put::put writes narrowed characters to output iterator
+void test02()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ typedef time_put<wchar_t> tp_type;
+
+ const wchar_t fmt[] = {
+ 0xa0, 0x103, 0xfc, 0xb3, 0xa0c3,
+ L'%', L'c'
+ };
+
+ const size_t len = sizeof(fmt) / sizeof(fmt[0]);
+ const size_t cmplen = wcschr(fmt, L'%') - fmt;
+
+ locale loc;
+ const tp_type& tp = use_facet<tp_type>(loc);
+ time_t tt = time(NULL);
+ wostringstream stream;
+
+ tp.put(tp_type::iter_type(stream), stream, stream.fill(),
+ localtime(&tt), fmt, fmt + len);
+ wstring str = stream.str();
+ VERIFY( str.length() >= cmplen );
+ VERIFY( !wmemcmp(str.data(), fmt, cmplen) );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_3.cc b/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_3.cc
new file mode 100644
index 0000000..0bcae33
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_put/put/wchar_t/12439_3.cc
@@ -0,0 +1,62 @@
+// Copyright (C) 2003 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 22.2.5.3.1 time_put members
+
+#include <locale>
+#include <sstream>
+#include <ctime>
+#include <testsuite_hooks.h>
+
+class TP : public std::time_put<wchar_t>
+{
+public:
+ mutable std::string format_chars;
+
+protected:
+ iter_type do_put(iter_type s, std::ios_base&, char_type fill,
+ const std::tm* t, char format, char modifier) const
+ {
+ format_chars.push_back(format);
+ return s;
+ }
+};
+
+// libstdc++/12439
+// time_put::put reads past end of format string
+void test03()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ wostringstream stream;
+ time_t tt = time(NULL);
+
+ const wchar_t* fmt = L"%c";
+
+ TP tp;
+ tp.put(TP::iter_type(stream), stream, stream.fill(), localtime(&tt),
+ fmt, fmt + 1);
+ VERIFY( tp.format_chars.empty() );
+}
+
+int main()
+{
+ test03();
+ return 0;
+}