v1.61 CyArtFileMgr().getXXXXArtInfo(name) crash on wrong tag name.

SimCutie

Warlord
Joined
Dec 10, 2005
Messages
197
CyArtFileMgr().getXXXArtInfo("art_tag") will crash (CTD) if the art_tag is wrong tag. It should return NULL, not crash.
For example, CyArtFileMgr().getInterfaceArtfo("wrong_name") will hang in infinite recursive call, and crash.
Lets see the CvGameCoreDLL SDK source code: It is macro defintion..
Code:
CvArtFileMgr.cpp: line 63 - line 83
CvArtInfo##name##* CvArtFileMgr::get##name##ArtInfo( [B]const char *szArtDefineTag [/B]) const \
{ \
	FAssertMsg(szArtDefineTag, "NULL string on art info lookup?"); \
	ArtInfo##name##MapType::const_iterator it = m_map##name##ArtInfos->find( szArtDefineTag );\
	if ( it == m_map##name##ArtInfos->end() ) \
	{\
		char szErrorMsg[256]; \
		sprintf(szErrorMsg, "get##name##ArtInfo: %s was not found", szArtDefineTag); \
		FAssertMsg(false, szErrorMsg ); \
		if ( [B]szArtDefineTag == "ERROR" [/B]) \
		{ \
			return NULL; \
		} \
		else \
		{ \
			return get##name##ArtInfo( "ERROR" ); \
		} \
	} \
	return it->second; \
} \
CvArtInfo##name##& CvArtFileMgr::get##name##ArtInfo(int i) { return m_pa##name##ArtInfo[i]; }
The line marked with bold (line 72) is obviously wrong C++ statement. Data type of szArtDefineTag is const char *. You can not use == operator to compare with constant string "ERROR".
This make it evalued to always false and fall into else part and infinite recursive call to itself and crash.
The right line sholde be like this:
Code:
line 72:
BEFORE:
	if ( szArtDefineTag == "ERROR" ) \
AFTER:
	if ( strcmp(szArtDefineTag, "ERROR") == 0 ) \
 
Very cool, nice find! Has this been reported to Firaxis?
 
Thanks, SimCutie, for reporting this errror. Is it true that the example provided is the only known instance of this type of error? I repaired the error noted for Line 72, and I'm hoping I won't have to sift through the entire file looking for other such instances (but I will if necessary).

Spocko
 
It seems this error has been corrected for Warlords. I opened CyArtFileMgr.cpp and the file looks different than that for 1.61. Unless they moved the error somewhere else :)
 
Top Bottom