This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: std::string clobbers memory when compiling without optimizations
- From: Henrik MannerstrÃm <henrik dot mannerstrom at gmail dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 03 Oct 2014 13:08:57 +0300
- Subject: Re: std::string clobbers memory when compiling without optimizations
- Authentication-results: sourceware.org; auth=none
- References: <542E5BF1 dot 2070508 at gmail dot com> <CAH6eHdS_TJdXkp55r8P13q_9ScThVu8LG9mp-5PPqBimb2P90Q at mail dot gmail dot com>
Hi,
On 10/03/2014 12:58 PM, Jonathan Wakely wrote:
> Have you tried valgrind? Or compiling with GCC's -fstack-protector
> option? I can't reproduce the problem, and I think it's pretty
> unlikely std::string has that kind of bug without someone noticing
> years ago.
I'm not assuming that std::string has a bug (even though the title might
suggest that), I'm just saying that the gdb watchpoint is triggered
inside that function. I tried valgrind memcheck, but I'm no expert, so
suggestions are welcome. Below is the output with stack-protector, what
do you make out of it? Could it be my installation?
- Henrik
$ g++-4.9 -std=gnu++1y mvu.cc -o mvu
$ ./mvu
Correct diagonal: 1 1 1
Eigen::Matrix<double, 1, 3, 1, 1, 3>
Incorrect diagonal: 1.81749e-316 1 1
$ g++-4.9 -std=gnu++1y -fstack-protector-all mvu.cc -o mvu
$ ./mvu
Correct diagonal: 1 1 1
Eigen::Matrix<double, 1, 3, 1, 1, 3>
Incorrect diagonal: 1 2 3
$ g++-4.9 -std=gnu++1y -O1 -fstack-protector-all mvu.cc -o mvu
$ ./mvu
Correct diagonal: 1 1 1
Eigen::Matrix<double, 1, 3, 1, 1, 3>
Incorrect diagonal: 1 1 1
g++-4.9 (Ubuntu 4.9.1-3ubuntu2~14.04.1) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.