Add security checks on file writting
This commit is contained in:
parent
a8e63b9724
commit
df84f93938
2 changed files with 56 additions and 51 deletions
|
@ -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");
|
||||||
|
@ -941,6 +943,7 @@ void ExportWaveAsCode(Wave wave, const char *fileName)
|
||||||
fprintf(txtFile, "0x%x };\n", ((unsigned char *)wave.data)[dataSize - 1]);
|
fprintf(txtFile, "0x%x };\n", ((unsigned char *)wave.data)[dataSize - 1]);
|
||||||
|
|
||||||
fclose(txtFile);
|
fclose(txtFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Play a sound
|
// Play a sound
|
||||||
|
|
|
@ -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");
|
||||||
|
@ -881,6 +882,7 @@ void ExportImageAsCode(Image image, const char *fileName)
|
||||||
fprintf(txtFile, "0x%x };\n", ((unsigned char *)image.data)[dataSize - 1]);
|
fprintf(txtFile, "0x%x };\n", ((unsigned char *)image.data)[dataSize - 1]);
|
||||||
|
|
||||||
fclose(txtFile);
|
fclose(txtFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy an image to a new image
|
// Copy an image to a new image
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue