From: Thilo Schulz Date: Sat, 10 Oct 2015 11:06:04 +0000 (+0200) Subject: Fix segfault crash if output file cannot be opened X-Git-Tag: v1.3rc1~18 X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=commitdiff_plain;h=701c887bf37084b271eb1df392e2aa9f33452dd7 Fix segfault crash if output file cannot be opened --- diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c index edcfad7..0d75c24 100644 --- a/ftdi_eeprom/main.c +++ b/ftdi_eeprom/main.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -395,10 +396,15 @@ int main(int argc, char *argv[]) } if (filename != NULL && strlen(filename) > 0) { - FILE *fp = fopen (filename, "wb"); - fwrite (eeprom_buf, 1, my_eeprom_size, fp); - fclose (fp); + + if(fp) + { + fwrite(eeprom_buf, 1, my_eeprom_size, fp); + fclose(fp); + } + else + fprintf(stderr, "Could not open output file %s: %s\n", filename, strerror(errno)); } else {