Linux world crashes loading new items

Old bugs stored here for reference.
Locked
User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Linux world crashes loading new items

Post by John Adams » Tue Jan 15, 2013 3:52 pm

I think this is happening because now, there is some data for certain types of items - in this case, Books. I am not sure yet what the data problems are, but I am looking into that. This bug/issue though seems to be related to how we're loading book "text" into the book_info structs.

Crash:
Program received signal SIGSEGV, Segmentation fault.
0xb7f80178 in std::string::assign(char const*, unsigned int) () from /usr/lib/libstdc++.so.6
(gdb) bt
#0 0xb7f80178 in std::string::assign(char const*, unsigned int) () from /usr/lib/libstdc++.so.6
#1 0x081ca794 in std::string::assign (this=0x839f060) at /usr/include/c++/4.4/bits/basic_string.h:970
#2 std::string::operator= (this=0x839f060) at /usr/include/c++/4.4/bits/basic_string.h:514
#3 WorldDatabase::LoadBooks (this=0x839f060) at Items/ItemsDB.cpp:371
#4 0x081d1c4b in WorldDatabase::LoadItemList (this=0x839f060) at Items/ItemsDB.cpp:797
#5 0x081fe362 in main (argc=1, argv=0xbffff824) at net.cpp:208

Code: Select all

int32 WorldDatabase::LoadBooks()
{
	DatabaseResult result;
	int32 total = 0;
	int32 id = 0;

	if( database_new.Select(&result, "SELECT item_id, language, author, title FROM item_details_book") )
	{
		while( result.Next() )
		{
			id = result.GetInt32Str("item_id");
			Item* item = master_item_list.GetItem(id);

			if(item)
			{
				LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Book for item_id %u", id);
				LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %s, %s", 
					ITEM_TYPE_BOOK, 
					result.GetInt8Str("language"), 
					result.GetStringStr("author"), 
					result.GetStringStr("title"));

				item->SetItemType(ITEM_TYPE_BOOK);
				item->book_info->language = result.GetInt8Str("language");
				item->book_info->author.data = result.GetStringStr("author");
				item->book_info->author.size = item->book_info->author.data.length();
				item->book_info->title.data = result.GetStringStr("title");
				item->book_info->title.size = item->book_info->title.data.length();
				total++;
			}
			else
				LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_book`, ID: %i", id);
		}
	}

	return total;
}
Specifically

Code: Select all

				item->book_info->author.data = result.GetStringStr("author");
				item->book_info->author.size = item->book_info->author.data.length();
This is crashing when the "author" field has no length - it is not NULL, but does not appear to have any valid data. I tried updating the function to the DatabaseNew class, and it still crashes right here as well. I wanted to post it to learn why... because hacking it to "just work" is never good enough for me ;) need to understand why this happens.

Meanwhile, I'm just going to wrap it in an if to see if the field has data before trying to stuff it. Btw, this does NOT happen on Windows. Only Linux, and until CoE, we had no data for books - so this has probably existed all along.

Input appreciated.

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: Linux world crashes loading new items

Post by John Adams » Tue Jan 15, 2013 4:04 pm

This is my fix, seems to work...

Code: Select all

				if(strlen(result.GetStringStr("author")) > 0)
				{
					item->book_info->author.data = result.GetStringStr("author");
					item->book_info->author.size = item->book_info->author.data.length();
				}

				if(strlen(result.GetStringStr("title")) > 0)
				{
					item->book_info->title.data = result.GetStringStr("title");
					item->book_info->title.size = item->book_info->title.data.length();
				}
but I fear that leaves those values uninitialized, and they'll probably crash somewhere else :)

Locked

Who is online

Users browsing this forum: No registered users and 0 guests