fix segfault
[compress.git] / compress.c
index d27f8e5740982070b6383f5cc10cbef86ad52fd5..f92393a47102e56e227cdfd9b2d6a86a4c9c3f5c 100644 (file)
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: atoi.o code.o debug.o fprintf.o */
+/* linker: atoi.o code.o debug.o fdprintf.o */
 
 #include <fcntl.h>
 #include <unistd.h>
@@ -8,7 +8,7 @@
 #include "atoi.h"
 #include "code.h"
 #include "debug.h"
-#include "fprintf.h"
+#include "fdprintf.h"
 
 /* constants */
 
@@ -31,7 +31,7 @@ char *progname = NULL;
 
 int usage (int ret)
 {
-    int fd = ret ? _fderr : _fdout;
+    int fd = ret ? stdfderr : stdfdout;
     fdprintf (fd, "usage: %s\n", progname);
     fdprintf (fd, " -h : help message\n");
     fdprintf (fd, " -i <file>: input file\n");
@@ -94,7 +94,7 @@ void print_occ_table (int *table)
 
 leaf_t **init_forest (int *table)
 {
-    static leaf_t *leafs[NB_BYTES] = {0};
+    static leaf_t *leafs[NB_BYTES + 1] = {0};
     int nb_leafs = 0;
     int i, l;
 
@@ -713,7 +713,7 @@ int main (int argc, char *argv[])
                 PRINTERR ("%s: missing verbose level\n", progname);
                 return usage (1);
             }
-            verbose = myatoi (arg);
+            verbose = atoi (arg);
             VERBOSE (INFO, PRINTOUT ("verbose: %d\n", verbose));
             break;
         case 'h':
@@ -760,10 +760,14 @@ int main (int argc, char *argv[])
 // test: compress.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
 // test: compress.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
 // test: compress.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
+// test: compress.exe -v 2>&1 | grep -q 'missing verbose level'
+// test: compress.exe -c -i compress.c 2>&1 | grep -q 'missing file'
+// test: compress.exe -c -v 4 -i compress.c -o compress.mz | grep -q "Occurence table"
 // test: compress.exe -c -i compress.c -o compress.mz
 // test: ls -sS1 compress.c compress.mz | tail -1 | grep compress.mz
 // test: compress.exe -d -i compress.mz -o tmp.c
-// test: cmp compress.c tmp.c
-// test: rm compress.mz tmp.c
+// test: cmp compress.c tmp.c; x=$?; rm compress.mz tmp.c; test x$x = x0
+// test: compress.exe -c -i test/compress.c -o compress.mz 2>&1 | grep "can't open file"
+// test: compress.exe -c -i compress.c -o test/compress.mz 2>&1 | grep "can't open file"
 
 /* vim: set ts=4 sw=4 et: */