[Bug c++/31314] New: Segmentation fault when assign std::string to another std::string when using std::vector and inheritance

2007-03-22 Thread wmacura at gmail dot com
Short version:
Assigning an index from a vectorstring to a local string works. Assigning to
a private class member of type string fails with a segmentation fault
apparently caused by a delete[].

I've managed to simplify the test case quite substantially for this bug, but
its still quite convoluted. For this I apologize.


Long version:

Here's a summary of the example: its supposed to be a framework for
implementing model-view-controller type applications in C++. The code is a
foundation for a GTKmm application. We have the Database:: interface which is
implemented by Sqlite::. Each model inherits from the Model:: base class which
is modeled very loosely on the ActiveRecord system in Ruby-on-Rails. The User::
class is a model.

Queries on the database are run through Database::exec() which really is
Sqlite::exec(). The findall() function called in main() is purportedly part of
User:: but actually implemented in Model::.



Now, for the bug.

The example causes a SIGSEGV in User::findall() (ie. Model::findall()). But the
shocker is where it happens: line 130 in the example. We've run Sqlite::exec(),
and gotten a vector of strings. We can also loop over the vector and print each
string.

I have no idea why this bug occurs in this specific code. The only thing
remotely unusual is the inheritance pattern (ie. class User: public ModelUser
{} ), but that's not particularly bizarre either.


-- 
   Summary: Segmentation fault when assign std::string to another
std::string when using std::vector and inheritance
   Product: gcc
   Version: 4.1.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: wmacura at gmail dot com


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



[Bug c++/31314] Segmentation fault when assign std::string to another std::string when using std::vector and inheritance

2007-03-22 Thread wmacura at gmail dot com


--- Comment #1 from wmacura at gmail dot com  2007-03-22 15:58 ---
Created an attachment (id=13252)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13252action=view)
Testcase (seg at line 130)

Build instruction:

 g++ -g stringtest.cpp -o stringtest


-- 


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



[Bug c++/31314] Segmentation fault when assign std::string to another std::string when using std::vector and inheritance

2007-03-22 Thread wmacura at gmail dot com


--- Comment #3 from wmacura at gmail dot com  2007-03-22 16:46 ---
Subject: Re:  Segmentation fault when assign std::string to another std::string
when using std::vector and inheritance

:-o

Damn. Construct() was a static function for a while and I didn't
notice this when I started butchering the code.

Thanks.

Wiktor

On 22 Mar 2007 16:34:01 -, pinskia at gcc dot gnu dot org
[EMAIL PROTECTED] wrote:


 --- Comment #2 from pinskia at gcc dot gnu dot org  2007-03-22 16:34 
 ---
 The problem is with:
 Row r = r.construct(rawdata.at(i));


 You are using r before it is constructored.

 This is not a bug in GCC but in your code.


 --

 pinskia at gcc dot gnu dot org changed:

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


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

 --- You are receiving this mail because: ---
 You reported the bug, or are watching the reporter.



-- 


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