ROMReader: fix specified bound depends on the length of the source argument

It seems gcc have a (new ?) warning that doesn't allow *ncpy functions
to have any source length related value as len argument.

I've use strdunp to fix this, but I guess there is some other solutions
that doesn't require free.
use c++ strings ?
use strcpy(...); tmp1[strlen(filename) - 4] = 0; ... ?
remove the warning in the Makefile ?

but as the strdump solution is simple enouth I've keep this.
This commit is contained in:
matthias gatto 2018-10-11 23:56:27 +02:00
parent 8c6c2e8071
commit 50755c6a45
1 changed files with 4 additions and 3 deletions

View File

@ -238,12 +238,13 @@ void * ZIPROMReaderInit(const char * filename)
ZZIP_DIRENT * dirent = zzip_readdir(dir);
if (dir != NULL)
{
char tmp1[1024];
char *tmp1;
char tmp2[1024];
memset(tmp1,0,sizeof(tmp1));
memset(tmp2,0,sizeof(tmp2));
strncpy(tmp1, filename, strlen(filename) - 4);
tmp1 = strndup(filename, strlen(filename) - 4);
sprintf(tmp2, "%s/%s", tmp1, dirent->d_name);
free(tmp1);
return zzip_fopen(tmp2, "rb");
}
return NULL;