Skip to content

Commit

Permalink
fix: change malloc of filename with FILENAME_MAX size
Browse files Browse the repository at this point in the history
  • Loading branch information
alekmaul committed Sep 29, 2023
1 parent 48b6352 commit 1c0c8cf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tools/gfx4snes/src/images.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void image_load_png(const char *filename, t_image *img, bool isquiet)
char *outputname;

// prepare file extension
outputname=(char *) malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
outputname=(char *) malloc(FILENAME_MAX); //malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
if(outputname==NULL)
{
fatal("can't allocate memory for png filename");
Expand Down Expand Up @@ -155,7 +155,7 @@ void image_load_bmp(const char *filename, t_image *img, bool isquiet)
unsigned int bmperror; // error management

// prepare file extension
outputname=(char *) malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
outputname=(char *) malloc(FILENAME_MAX); //malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
if(outputname==NULL)
{
fatal("can't allocate memory for bmp filename");
Expand Down
2 changes: 1 addition & 1 deletion tools/gfx4snes/src/maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void map_save (const char *filename, unsigned short *map,int snesmode, int nbtil
int i;

// remove extension and put the ".map/mp7" to filename
outputname=(char *) malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
outputname=(char *) malloc(FILENAME_MAX); //malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
if(outputname==NULL)
{
fatal("can't allocate memory for map filename");
Expand Down
2 changes: 1 addition & 1 deletion tools/gfx4snes/src/palettes.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void palette_save (const char *filename, int *palette,int nbcolors, bool isquiet
int i;

// remove extension and put the ".pal" to filename
outputname=(char *) malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
outputname=(char *) malloc(FILENAME_MAX); //malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
if(outputname==NULL)
{
fatal("can't allocate memory for palette filename");
Expand Down
4 changes: 2 additions & 2 deletions tools/gfx4snes/src/tiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void tiles_save (const char *filename, unsigned char *tiles,int nbtiles, int nbc
int bufsize,bufsizeout;

// remove extension and put the ".map/mp7" to filename
outputname=(char *) malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
outputname=(char *) malloc(FILENAME_MAX); //malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
if(outputname==NULL)
{
fatal("can't allocate memory for tiles filename");
Expand Down Expand Up @@ -264,7 +264,7 @@ void tiles_savepacked (const char *filename, unsigned char *tiles,int tilesnumbe
int i;

// remove extension and put the ".map/mp7" to filename
outputname=(char *) malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
outputname=(char *) malloc(FILENAME_MAX); //malloc(strlen(filename)+4); // 4 to be sure to have enough for extension
if(outputname==NULL)
{
fatal("can't allocate memory for packed tiles filename");
Expand Down

0 comments on commit 1c0c8cf

Please sign in to comment.