CARD_Init() crash
Posted: Tue Jul 12, 2011 4:01 am
CARD_Init() takes two parameters: the game code and the company name. The documentation reads:
However, doing:
...triggers a crash. The problem is in card.c lines 2449 - 2450:
Specifically, the problem is the use of strlen(). It appears then that CARD_Init() expects NULL terminated strings, but specifies explicitly the length in bytes of the string in the documentation. The use of the word 'bytes' as opposed to 'characters' and the lack of mention of a required NULL termination is a problem. Either the documentation or the implementation needs to change to match the other. I suggest simply rewording the documentation to read:
Code: Select all
Performs the initialization of the memory card subsystem.
Parameters:
gamecode pointer to a 4byte long string to specify the vendors game code. May be NULL
company pointer to a 2byte long string to specify the vendors company code. May be NULL
Code: Select all
char gamecode[4] = { 'a' , 'b', 'c', 'd' };
char company[2] = { '1', '2' };
CARD_Init(gamecode, company);
Code: Select all
if(gamecode && strlen(gamecode)<=4) memcpy(card_gamecode,gamecode,4);
if(company && strlen(company)<=2) memcpy(card_company,company,2);
Code: Select all
gamecode pointer to a 4 character NULL-terminated string to specify the vendors game code. May be NULL.
company pointer to a 2 character NULL-terminated string to specify the vendors company code. May be NULL.