OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc3/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_streambuf/] [sync/] [wchar_t/] [1057.cc] - Blame information for rev 516

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// 1999-10-11 bkoz
2
 
3
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009
4
// Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
 
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
 
17
// You should have received a copy of the GNU General Public License along
18
// with this library; see the file COPYING3.  If not see
19
// <http://www.gnu.org/licenses/>.
20
 
21
 
22
// 27.5.2 template class basic_streambuf
23
 
24
#include <streambuf>
25
#include <string>
26
#include <testsuite_hooks.h>
27
 
28
class setpbuf : public std::wstreambuf
29
{
30
  wchar_t       buffer[4];
31
  std::wstring  result;
32
 
33
public:
34
 
35
  std::wstring&
36
  get_result()
37
  { return result; }
38
 
39
  setpbuf()
40
  {
41
    wchar_t foo[32];
42
    setp(foo, foo + 32);
43
    setp(buffer, buffer + 4);
44
  }
45
 
46
  ~setpbuf()
47
  { sync(); }
48
 
49
  virtual int_type
50
  overflow(int_type n)
51
  {
52
    if (sync() != 0)
53
      return traits_type::eof();
54
 
55
    result += traits_type::to_char_type(n);
56
 
57
    return n;
58
  }
59
 
60
  virtual int
61
  sync()
62
  {
63
    result.append(pbase(), pptr());
64
    setp(buffer, buffer + 4);
65
    return 0;
66
  }
67
};
68
 
69
// libstdc++/1057
70
void test04()
71
{
72
  bool test __attribute__((unused)) = true;
73
  std::wstring text = L"abcdefghijklmn";
74
 
75
  // 01
76
  setpbuf sp1;
77
  // Here xsputn writes over sp1.result
78
  sp1.sputn(text.c_str(), text.length());
79
 
80
  // This crashes when result is accessed
81
  sp1.pubsync();
82
  VERIFY( sp1.get_result() == text );
83
 
84
  // 02
85
  setpbuf sp2;
86
  for (std::wstring::size_type i = 0; i < text.length(); ++i)
87
    {
88
      // sputc also writes over result
89
      sp2.sputc(text[i]);
90
    }
91
 
92
  // Crash here
93
  sp2.pubsync();
94
  VERIFY( sp2.get_result() == text );
95
}
96
 
97
int main()
98
{
99
  test04();
100
  return 0;
101
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.