GameMonkey Script

GameMonkey Script Forums
It is currently Mon Nov 20, 2017 3:24 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GetTypeId... broken?
PostPosted: Mon Jun 13, 2011 3:50 pm 
Offline

Joined: Mon Feb 28, 2011 8:06 pm
Posts: 12
The function gmMachine::GetTypeId(const char* a_typename) uses the following line of code to do typename comparisons:

Code:
if( strcmp((const char *)m_types[id].m_name, a_typename) == 0 )
...


However, this does not seem to be a valid comparison. If we look in the function gmMachine::CreateUserType(const char * a_name), we see that m_name is in fact a gmStringObject*, not a char*, and so the comparison would only be valid by extremely rare happenstance.

I replaced the comparison with the following, and it started working as expected:

Code:
if( strcmp(((gmStringObject *)m_types[id].m_name)->GetString(), a_typename) == 0 )
...


Top
 Profile  
Reply with quote  
 Post subject: Re: GetTypeId... broken?
PostPosted: Thu Jun 16, 2011 3:11 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
Thank Tiok, looks like you are correct. Although gmStringObject implements operator const char*, that would not be called using the current syntax.
It would have worked with
Code:
if( strcmp((const char *)(*m_types[id].m_name), a_typename) == 0 )
Nice find :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group