CARD_Init() crash

Post Reply
figgles
Posts: 5
Joined: Thu Jun 30, 2011 8:40 pm

CARD_Init() crash

Post by figgles » Tue Jul 12, 2011 4:01 am

CARD_Init() takes two parameters: the game code and the company name. The documentation reads:

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
However, doing:

Code: Select all

char gamecode[4] = { 'a' , 'b', 'c', 'd' };
char company[2] = { '1', '2' };
CARD_Init(gamecode, company);
...triggers a crash. The problem is in card.c lines 2449 - 2450:

Code: Select all

if(gamecode && strlen(gamecode)<=4) memcpy(card_gamecode,gamecode,4);
if(company && strlen(company)<=2) memcpy(card_company,company,2);
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

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.

tueidj
Posts: 40
Joined: Thu Dec 10, 2009 9:26 am

Re: CARD_Init() crash

Post by tueidj » Mon Jul 25, 2011 4:05 pm

Given that this is documentation for C code, I would have assumed "string" implied null termination.

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: CARD_Init() crash

Post by WinterMute » Mon Jul 25, 2011 4:11 pm

To be fair I think we can probably dispense with the strlen - these functions basically use 4 and 2 byte arrays rather than actual strings.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests