[BUG] valarray_copy, with mask_array, libstdc++-v3

Luke Kenneth Casson Leighton lkcl@samba-tng.org
Wed Jul 3 15:45:00 GMT 2002


dear sirs,

i noticed that code like this:

valarray<bool> b(4);
b[0] = false;
b[1] = true;
b[2] = true;
b[0] = false;

valarray<int> i(4);
valarray<int> j;
i = 9;

j = i[b];

should create an array (j) of two items.

instead, it overwrites memory and corrupts things
because... well... here's a patch :)

if you use valarray<some_complicated_class_with_lots_of_memory>
then this bug becomes really, really obvious and serious.

please acknowledge receipt of this message.  if not received
will assume lost/ignored and will find other contact means.

l.

--- /usr/include/g++-3/std/std_valarray.h	Wed Jul  3 21:49:02 2002
+++ /tmp/x	Wed Jul  3 21:49:08 2002
@@ -374,7 +374,7 @@
 valarray<_Tp>::operator= (const mask_array<_Tp>& __ma)
 {
     __valarray_copy (__ma._M_array, __ma._M_mask,
-                     _Array<_Tp>(_M_data), _M_size);
+                     _Array<_Tp>(_M_data), __ma._M_sz);
     return *this;
 }
 


-- 
----------------------------------------------------------
this message is private, confidential, and is intented for
the specified recipients only.  if you received in error,
altered, deleted, modified, destroyed or interfered with
the contents of this message, in whole or in part, please
inform the sender (that's me), immediately.

if you, the recipient, reply to this message, and do not
then receive a response, please consider your reply to have
been lost or deliberately destroyed: i *always* acknowledge
personal email received.  please therefore take appropriate
action and use appropriate protocols to ensure effective
communication.

thank you.



More information about the Gcc mailing list