public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/13624] New: Unsafe delimiter in ostream_iterator
@ 2004-01-09  4:35 jlquinn at gcc dot gnu dot org
  2004-01-09  6:19 ` [Bug libstdc++/13624] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jlquinn at gcc dot gnu dot org @ 2004-01-09  4:35 UTC (permalink / raw)
  To: gcc-bugs

An ostream_iterator constructed with a stream delimiter will break if the string
is destroyed since the class just stores a pointer to the constructor argument.
 I.e.

char *x = new char[4];
strcpy(x, "ugh");
ostream_iterator<int> it(cout, x);
delete[] x;
*it = 5;

A copy needs to be made for safety.  Present in 3.2, 3.3 as well.

-- 
           Summary: Unsafe delimiter in ostream_iterator
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jlquinn at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13624


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/13624] Unsafe delimiter in ostream_iterator
  2004-01-09  4:35 [Bug libstdc++/13624] New: Unsafe delimiter in ostream_iterator jlquinn at gcc dot gnu dot org
@ 2004-01-09  6:19 ` pinskia at gcc dot gnu dot org
  2004-01-09 13:41 ` peturr02 at ru dot is
  2004-01-15  9:26 ` paolo at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-09  6:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-09 06:19 -------
I do not know if this is a bug (24.5.2.1 P2):
ostream_iterator(ostream_type& s, const charT* delimiter);
2 Effects: Initializes out_stream with s and delim with delimiter. 

What does it mean by "initializes".

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13624


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/13624] Unsafe delimiter in ostream_iterator
  2004-01-09  4:35 [Bug libstdc++/13624] New: Unsafe delimiter in ostream_iterator jlquinn at gcc dot gnu dot org
  2004-01-09  6:19 ` [Bug libstdc++/13624] " pinskia at gcc dot gnu dot org
@ 2004-01-09 13:41 ` peturr02 at ru dot is
  2004-01-15  9:26 ` paolo at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: peturr02 at ru dot is @ 2004-01-09 13:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From peturr02 at ru dot is  2004-01-09 13:41 -------
> ostream_iterator(ostream_type& s, const charT* delimiter);
> 2 Effects: Initializes out_stream with s and delim with delimiter. 

Taken at face value, this means that the constructor should be defined
"as if":

  ostream_iterator(ostream_type& s, const charT* delimiter)
  : out_stream(s), delim(delimiter) { }

and since delim is of type const charT*, no copy will be made, so I
think the current implementation is correct. A conforming program *can*
find out if the string is copied (by modifying the charT array after
construction of the ostream_iterator), so there isn't much choice here.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13624


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/13624] Unsafe delimiter in ostream_iterator
  2004-01-09  4:35 [Bug libstdc++/13624] New: Unsafe delimiter in ostream_iterator jlquinn at gcc dot gnu dot org
  2004-01-09  6:19 ` [Bug libstdc++/13624] " pinskia at gcc dot gnu dot org
  2004-01-09 13:41 ` peturr02 at ru dot is
@ 2004-01-15  9:26 ` paolo at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: paolo at gcc dot gnu dot org @ 2004-01-15  9:26 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 428 bytes --]


------- Additional Comments From paolo at gcc dot gnu dot org  2004-01-15 09:26 -------
Hi concur with Pétur, not a bug.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13624


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-01-15  9:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-09  4:35 [Bug libstdc++/13624] New: Unsafe delimiter in ostream_iterator jlquinn at gcc dot gnu dot org
2004-01-09  6:19 ` [Bug libstdc++/13624] " pinskia at gcc dot gnu dot org
2004-01-09 13:41 ` peturr02 at ru dot is
2004-01-15  9:26 ` paolo at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).