Why does this crash? ...still crashing...

A forum for feature requests/discussions and user submitted patches that improve MQ2

Moderator: MacroQuest Developers

Amadeus
The Maestro
The Maestro
Posts: 2036
Joined: Sat Jun 29, 2002 3:51 pm

Why does this crash? ...still crashing...

Post by Amadeus » Sat Feb 15, 2003 1:27 am

Hmmm...this is rather "out of context"..but, why would it crash EQ?

Code: Select all

			CHAR ZoneName[] = {0};
			sprintf( ZoneName, "%s", CharLower(Zone.ZoneNameShort));

			
			static const char* zoneNames[] = 
			{
				#include "zones.h"   //taken from ShowEQ source
			};

			for (int i = 0; i < (sizeof(zoneNames) / sizeof (char*)); i++) {
				
				if (ZoneName == zoneNames[i]) {
					zoneID = i;
				}
			}
I have put in debugging lines that post to the log file that CONFIRMS that at one point in the for loop, it is checking 'butcher' against 'butcher'; however, it just skips over it (as if the 'if' statement doesn't exist) ..and the whole thing crashes.

I have also used various other things in place of ZoneName == zoneNames (ie, stricmp())....all seem to crash EQ.
Last edited by Amadeus on Sat Feb 15, 2003 11:28 am, edited 1 time in total.

Lax
We're not worthy!
We're not worthy!
Posts: 3524
Joined: Thu Oct 17, 2002 1:01 pm
Location: ISBoxer
Contact:

Post by Lax » Sat Feb 15, 2003 9:11 am

Code: Select all

         CHAR ZoneName[] = {0}; 
this makes an array of size 1, with the only element set to null. You want one the size of strlen(Zone.ZoneNameShort) which is guaranteed larger than 1. You can make it a char[128] or something and it will stop crashes.. and just take out the part about setting 0 because its going to get scrapped by the sprintf.

You should also use strcmp or stricmp, because directly comparing ZoneName with ZoneNames is not going to have your intended result
Lax Lacks
Master of MQ2 Disaster
Purveyor of premium, EULA-safe MMORPG Multiboxing Software
* Multiboxing with ISBoxer: Quick Start Video
* EQPlayNice, WinEQ 2.0

Amadeus
The Maestro
The Maestro
Posts: 2036
Joined: Sat Jun 29, 2002 3:51 pm

Post by Amadeus » Sat Feb 15, 2003 11:29 am

Ok ...modified the code. Still crashes EQ very hard when I try this routine.

Code: Select all

			CHAR ZoneName[MAX_STRING];
			sprintf( ZoneName, "%s", CharLower(Zone.ZoneNameShort));
		
			static const char* zoneNames[] = 
			{
				#include "zones.h"   //taken from ShowEQ source
			};

			for (int i = 0; i < (sizeof(zoneNames) / sizeof (char*)); i++) {
				
				if (!stricmp(ZoneName, zoneNames[i] ) ) {
					zoneID = i;
				}
			}

User avatar
dont_know_at_all
Developer
Developer
Posts: 5450
Joined: Sun Dec 01, 2002 4:15 am
Location: Florida, USA
Contact:

Post by dont_know_at_all » Tue Feb 18, 2003 6:22 pm

stricmp cannot take NULL as an input:

Code: Select all

if (zoneNames[i] && !stricmp(ZoneName, zoneNames[i] ) ) {
    zoneID = i;
}

lifewolf
a ghoul
a ghoul
Posts: 143
Joined: Fri Oct 18, 2002 6:29 pm

Post by lifewolf » Tue Feb 18, 2003 9:19 pm

dont_know_at_all wrote:stricmp cannot take NULL as an input:

Code: Select all

if (zoneNames[i] && !stricmp(ZoneName, zoneNames[i] ) ) {
    zoneID = i;
}

Code: Select all

if (zoneNames[i] && !stricmp(ZoneName, zoneNames[i] ) ) {
    zoneID = i;
    break;
}
(you want to break the for loop after you find you zone id, otherwise if its the 4th one your going to be comparing around a hundred more senselessly)