List:MySQL++« Previous MessageNext Message »
From:Jonathan Wakely Date:December 27 2007 11:08pm
Subject:invalid iterator in lookups[]
View as plain text  
This one was caught by GCC's debug mode.

I don't fully understand these parts of the library yet, but it seems
that this sql_type_info initializer on line 81 of type_info.cpp:

	sql_type_info("NULL NOT NULL", typeid(void),

combined with line 144 in examples/resetdb.cpp:

		query.template_defaults["desc"] = mysqlpp::null;

causes map_.end() to be dereferenced here in type_info.h

	const unsigned char& operator [](
			const std::type_info& ti) const
		return map_.find(&ti)->second;

Since the sql_type_info for typeid(void) doesn't have the tf_default
flag it isn't in the map, so the lookup fails.

After applying the patch below, if the iterator dereference on the
next line is valid the assertion will never fail, but resetdb fails
like so:

Connecting to database server...
Dropping existing sample data tables...
Creating stock table...
resetdb: ./lib/type_info.h:117: const unsigned char&
std::type_info&) const: Assertion `map_.find(&ti) != map_.end()'

Program received signal SIGABRT, Aborted.
0x00000032f8830ec5 in raise () from /lib64/
(gdb) bt
#0  0x00000032f8830ec5 in raise () from /lib64/
#1  0x00000032f8832970 in abort () from /lib64/
#2  0x00000032f882a11f in __assert_fail () from /lib64/
#3  0x00002aaaaab2cb5d in
(this=0x2aaaaad4c460, ti=@0x32fd6eb220) at ./lib/type_info.h:117
#4  0x00002aaaaab2cba6 in mysql_type_info (this=0x7fff89657dc7,
t=@0x32fd6eb220) at ./lib/type_info.h:168
#5  0x00002aaaaab287e8 in mysqlpp::SQLTypeAdapter::assign
(this=0x624048, n=@0x60bedd) at ./lib/stadapter.cpp:343
#6  0x00002aaaaab28877 in mysqlpp::SQLTypeAdapter::operator=
(this=0x624048, n=@0x60bedd) at ./lib/stadapter.cpp:435
#7  0x0000000000405b4c in main (argc=2, argv=0x7fff89658768) at

I have no idea whether this is a bug in resetdb or type_info.cpp or
what, so I'm afraid all I can do is report the problem.


Attachment: [text/x-patch] mysqlpp-typeinfo.patch
invalid iterator in lookups[]Jonathan Wakely28 Dec
  • Re: invalid iterator in lookups[]Warren Young28 Dec
    • Re: invalid iterator in lookups[]Jonathan Wakely28 Dec
      • Re: invalid iterator in lookups[]Warren Young3 Jan