Add security checks on file writting

This commit is contained in:
Ray 2019-09-30 17:32:06 +02:00
parent a8e63b9724
commit df84f93938
2 changed files with 56 additions and 51 deletions

View file

@ -910,6 +910,8 @@ void ExportWaveAsCode(Wave wave, const char *fileName)
FILE *txtFile = fopen(fileName, "wt"); FILE *txtFile = fopen(fileName, "wt");
if (txtFile != NULL)
{
fprintf(txtFile, "\n//////////////////////////////////////////////////////////////////////////////////\n"); fprintf(txtFile, "\n//////////////////////////////////////////////////////////////////////////////////\n");
fprintf(txtFile, "// //\n"); fprintf(txtFile, "// //\n");
fprintf(txtFile, "// WaveAsCode exporter v1.0 - Wave data exported as an array of bytes //\n"); fprintf(txtFile, "// WaveAsCode exporter v1.0 - Wave data exported as an array of bytes //\n");
@ -942,6 +944,7 @@ void ExportWaveAsCode(Wave wave, const char *fileName)
fclose(txtFile); fclose(txtFile);
} }
}
// Play a sound // Play a sound
void PlaySound(Sound sound) void PlaySound(Sound sound)

View file

@ -849,12 +849,13 @@ void ExportImageAsCode(Image image, const char *fileName)
{ {
#define BYTES_TEXT_PER_LINE 20 #define BYTES_TEXT_PER_LINE 20
FILE *txtFile = fopen(fileName, "wt");
if (txtFile != NULL)
{
char varFileName[256] = { 0 }; char varFileName[256] = { 0 };
int dataSize = GetPixelDataSize(image.width, image.height, image.format); int dataSize = GetPixelDataSize(image.width, image.height, image.format);
FILE *txtFile = fopen(fileName, "wt");
fprintf(txtFile, "\n");
fprintf(txtFile, "////////////////////////////////////////////////////////////////////////////////////////\n"); fprintf(txtFile, "////////////////////////////////////////////////////////////////////////////////////////\n");
fprintf(txtFile, "// //\n"); fprintf(txtFile, "// //\n");
fprintf(txtFile, "// ImageAsCode exporter v1.0 - Image pixel data exported as an array of bytes //\n"); fprintf(txtFile, "// ImageAsCode exporter v1.0 - Image pixel data exported as an array of bytes //\n");
@ -882,6 +883,7 @@ void ExportImageAsCode(Image image, const char *fileName)
fclose(txtFile); fclose(txtFile);
} }
}
// Copy an image to a new image // Copy an image to a new image
Image ImageCopy(Image image) Image ImageCopy(Image image)