Patch by Magliocchetti Riccardo:
introduce ARRAY_SIZE to calculate array size and use it instead of magic numbers.
This commit is contained in:
parent
2b7ce86880
commit
f544b5a7c3
|
@ -379,11 +379,11 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize,
|
|||
|
||||
/* I guess any directory can be used
|
||||
* so the current one should be ok */
|
||||
strncpy(szRomPath, ".", 512); /* "." is shorter then 512, yet strcpy should be avoided */
|
||||
strncpy(szRomPath, ".", ARRAY_SIZE(szRomPath));
|
||||
cflash_close();
|
||||
cflash_init( cflash_disk_image_file);
|
||||
|
||||
strncpy(szRomBaseName, filename,512);
|
||||
strncpy(szRomBaseName, filename, ARRAY_SIZE(szRomBaseName));
|
||||
|
||||
if(type == ROM_DSGBA)
|
||||
szRomBaseName[strlen(szRomBaseName)-strlen(DSGBA_EXTENSTION)] = 0x00;
|
||||
|
|
|
@ -259,7 +259,7 @@ static void list_files(char *fpath) {
|
|||
maxLevel++;
|
||||
fileLevel = maxLevel;
|
||||
|
||||
strncpy(DirSpec, fpath, 255+1); /* if we use strncpy, we use it correct to limit it by the internal, not input size */
|
||||
strncpy(DirSpec, fpath, ARRAY_SIZE(DirSpec));
|
||||
DirSpec[255] = 0 ; /* hard limit the string here */
|
||||
|
||||
hFind = FsReadFirst(DirSpec, &entry);
|
||||
|
@ -615,7 +615,7 @@ static u16 fread_buffered(int dirent,u32 cluster,u32 offset) {
|
|||
if (activeDirEnt != -1)
|
||||
fclose(hFile);
|
||||
|
||||
strncpy(fpath,sRomPath,256);
|
||||
strncpy(fpath,sRomPath,ARRAY_SIZE(fpath));
|
||||
strncat(fpath,DIR_SEP,256-strlen(fpath));
|
||||
|
||||
resolve_path(dirent);
|
||||
|
|
|
@ -654,7 +654,7 @@ int main(int argc, char ** argv) {
|
|||
#endif
|
||||
|
||||
/* // This has to get fixed yet
|
||||
strcpy(szRomPath, dirname(argv[1]));
|
||||
strncpy(szRomPath, dirname(argv[1]), ARRAY_SIZE(szRomPath));
|
||||
cflash_close();
|
||||
cflash_init();
|
||||
*/
|
||||
|
|
|
@ -1146,7 +1146,7 @@ int LoadFirmware(const char *filename)
|
|||
u32 size;
|
||||
FILE *f;
|
||||
|
||||
strncpy(FirmwareFile, filename, 256);
|
||||
strncpy(FirmwareFile, filename, ARRAY_SIZE(FirmwareFile));
|
||||
|
||||
f = fopen(filename, "rb");
|
||||
if(!f) return -1;
|
||||
|
|
|
@ -184,6 +184,8 @@ typedef int desmume_BOOL;
|
|||
#define MB(x) ((x)*1024*1024)
|
||||
#define KB(x) ((x)*1024)
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
#define CPU_STR(c) ((c==ARM9)?"ARM9":"ARM7")
|
||||
typedef enum
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue