Skip to content

Commit

Permalink
Fix SIGSEGV when can't writer output
Browse files Browse the repository at this point in the history
This fixes SIGSEGV (Segmentation Fault) when output file can't be opened for writting binary (wb). Instead display error message on what's wrong and exit with failure status (aka. errorlevel). This will make it more clear to user who forgot to "sudo" etc.
  • Loading branch information
MrKrzYch00 committed May 14, 2015
1 parent bea9526 commit 0f393c8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/zopfli/zopfli_bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Saves a file from a memory array, overwriting the file if it existed.
static void SaveFile(const char* filename,
const unsigned char* in, size_t insize) {
FILE* file = fopen(filename, "wb" );
if (file == NULL) {
fprintf(stderr,"Error: Cannot write to output file, terminating.\n");
exit (EXIT_FAILURE);
}
assert(file);
fwrite((char*)in, 1, insize, file);
fclose(file);
Expand Down

0 comments on commit 0f393c8

Please sign in to comment.