This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/35594] New: using vector::resize within a recursive function causes a crash
- From: "eda-qa at disemia dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Mar 2008 21:19:17 -0000
- Subject: [Bug c++/35594] New: using vector::resize within a recursive function causes a crash
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The below code fragment (.ii attached) causes a segmentation fault. I can't
see anything logically wrong with the code, but I am guessing an optimization
of the pointers within "out" are causing the problem: a reallocation occurs in
a deeper stack level, and the outer stack still maintains an old pointer.
However, since this code is logically valid, shouldn't it work, or shouldn't
there are least be some way for it to work? Or, am I missing something obvious
here.
My first attempt was to mark "vector" volatile, but I then can't call any of
its functions...
--
#include <vector>
using namespace std;
unsigned append( unsigned count, vector<unsigned>& out )
{
unsigned base = out.size();
unsigned need = count * 2;
out.resize( base + need );
unsigned at = base;
for( unsigned i = 0; i < count; i ++ )
{
out.at(at++) = i;
out.at(at++) = append( count-1, out );
}
return base;
}
int main()
{
vector<unsigned> v;
append( 50, v );
}
--
g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Linux version 2.6.22-1-mepis64-smp (root@mepis-pro) (gcc version 4.1.2 20061115
(prerelease) (Debian 4.1.1-21)) #1 SMP PREEMPT Mon Feb 18 23:03:02 EST 2008
--
Summary: using vector::resize within a recursive function causes
a crash
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: eda-qa at disemia dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35594