Memory Error in Class valarray

Radek Pecher r.pecher@rdr.leeds.ac.uk
Thu Feb 10 03:55:00 GMT 2000


Dear Sirs,

I am sending you a source code that causes a memory error in the 'valarray'
copy constructor.

The attached file 'Matrix.cpp' is the complete C++ code, no other headers or
preprocessing definitions are necessary. I wrote it for both the Borland C++
Builder 5 (console target; see the macro __TURBOC__) and the GNU GCC 2.95.
The Borland compilation of 'Matrix.cpp' results in the following correct
output:

0 2 3
{{11,12,13}, {21,22,23}}
{{7,7}, {7,7}, {7,7}}

whereas the GCC gives:

0 2 3
{{274184,12,13}, {274184,12,13}}
{{273040,7}, {273056,7}, {273056,7}}

I traced down this over-allocation bug to the 'new[]' operator in
'std/std_valarray.h' at line 303. This call corrupts the first members of
'_M_data' vector of argument 'const valarray<_Tp>& __v' of the copy
constructor 'valarray<_Tp>::valarray'.

I am also attaching file 'Matrix.out' generated by the command line
'c++ -ansi -v Matrix.cpp >&! Matrix.out' to show you the specifications of
our environment (gcc version 2.95.2 19991024, SunOS 5.7, SPARC Sun Solaris
2.7).

Please, would you be so kind and let me know when you recognise what is
going on there and how to correct it? Thank you very much. By the way: GCC
is an excellent software, and I am aware of the complexities that you must
deal with to make it work for so many different platforms!

Yours truly,
Radek
_________________________________________________

Dr. Radek Pecher
RDR, Earth Sciences
University of Leeds
Leeds, LS2 9JT
United Kingdom
TEL: +44 (0) 113 233 1926
FAX: +44 (0) 113 245 6233

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Matrix.out
Type: text/x-c
Size: 2289 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20000210/e86f140c/attachment.bin>


More information about the Gcc-bugs mailing list