Aww, be nice to users and don't segfault on them.  Patch attached that
adds a couple of sanity checks for dynamite.
diff -urNad orig/dynamite-0.1/src/dynamite.c dynamite-0.1/src/dynamite.c
--- orig/dynamite-0.1/src/dynamite.c    2006-01-19 03:40:14.043877731 +0200
+++ dynamite-0.1/src/dynamite.c 2006-01-19 04:11:37.969885851 +0200
@@ -1,6 +1,7 @@
 /* $Id: dynamite.c,v 1.1.1.1 2003/08/22 08:55:42 twogood Exp $ */
 #include "libdynamite.h"
 #include <stdio.h>
+#include <stdlib.h>
 
 #define FCLOSE(file)    if (file) { fclose(file); file = NULL; }
 
@@ -20,13 +21,38 @@
   return fwrite(buffer, 1, size, ((Cookie*)cookie)->output_file);
 }
 
+static void check_input(const char* filename, void* status)
+{
+  if (status == 0) {
+    fprintf(stderr, "dynamite: error opening file %s for input: ", filename);
+    perror(NULL);
+    exit(1);
+  }
+}
+
+static void check_output(const char* filename, void* status)
+{
+  if (status == 0) {
+    fprintf(stderr, "dynamite: error opening file %s for output: ", filename);
+    perror(NULL);
+    exit(1);
+  }
+}
+
 int main(int argc, char** argv)
 {
   int result = -1;
   Cookie cookie;
 
+  if (argc != 3) {
+    fprintf (stderr, "usage: dynamite <input_file> <output_file>\n");
+    exit(1);
+  }
+
   cookie.input_file   = fopen(argv[1], "r");
+  check_input(argv[1], cookie.input_file);
   cookie.output_file  = fopen(argv[2], "w");
+  check_output(argv[2], cookie.output_file);
 
   result = dynamite_explode(reader, writer, &cookie);
 

Reply via email to