Discussion:
[Libpqxx-general] Segmentation fault with C++11
Mario St-Gelais
2013-03-10 15:17:40 UTC
Permalink
I have this snippet of code that works fine when compiling with
g++ -g -o listpeople listpeople.cpp -I/usr/lib -lpqxx -lpq
but if adding the switch -std=gnu++11 or -std=c++11
I get segmentation fault when executed.
I use gcc 4.7.1 and Postgresql 9.2.1 on Slackware 14
--------------------------------------------------
int main(int, char *argv[])
{
Table T2("company");
T2.displayRows(2);
return 0;
}

void Table::displayRows(int interval){
using namespace std;
pqxx::connection c("dbname=mydb user=postgres");
pqxx::work txn(c);
string table=getName();
if(table[0]=='\0')
return;
const string select="SELECT * FROM " + getName();
pqxx::result r = txn.exec(select);
for (pqxx::result::const_iterator row = r.begin(), last = r.end(); row != last; ++row)
{
for (pqxx::result::tuple::const_iterator field = row->begin(), last = row->end(); field != last; ++field){
cout<<field<< " ";
}
cout<< endl;
}
}
------------------------------------------------
Debug output:
------------------------------------------------
(gdb)
1082 _M_erase(_S_right(__x));
(gdb)
std::_Rb_tree<std::string, std::pair<std::string const, pqxx::prepare::internal::prepared_def>, std::_Select1st<std::pair<std::string const, pqxx::prepare::internal::prepared_def> >, std::less<std::string>, std::allocator<std::pair<std::string const, pqxx::prepare::internal::prepared_def> > >::_S_right (__x=0xbfffe9f0) at /usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_tree.h:535
535 { return static_cast<_Link_type>(__x->_M_right); }
(gdb)
std::_Rb_tree<std::string, std::pair<std::string const, pqxx::prepare::internal::prepared_def>, std::_Select1st<std::pair<std::string const, pqxx::prepare::internal::prepared_def> >, std::less<std::string>, std::allocator<std::pair<std::string const, pqxx::prepare::internal::prepared_def> > >::_M_erase (this=0xbfffe9f0, __x=0xbfffe9f0)
at /usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_tree.h:1080
1080 while (__x != 0)
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x0804df92 in std::_Rb_tree<std::string, std::pair<std::string const, pqxx::prepare::internal::prepared_def>, std::_Select1st<std::pair<std::string const, pqxx::prepare::internal::prepared_def> >, std::less<std::string>, std::allocator<std::pair<std::string const, pqxx::prepare::internal::prepared_def> > >::_M_erase (this=0xbfffe9f0, __x=0xbfffe9f0)
at /usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_tree.h:1082
1082 _M_erase(_S_right(__x));

Continue reading on narkive:
Loading...