Index: trunk/Ohana/src/libfits/Makefile
===================================================================
--- trunk/Ohana/src/libfits/Makefile	(revision 38553)
+++ trunk/Ohana/src/libfits/Makefile	(revision 38986)
@@ -25,5 +25,4 @@
 TEST_CPPFLAGS =	$(BASE_CPPFLAGS)
 TEST_LDFLAGS  = $(BASE_LDFLAGS) -lFITS -lohana -ltap_ohana
-
 
 TESTXTRA = tcomptiming 
Index: trunk/Ohana/src/libfits/extern/gzip.c
===================================================================
--- trunk/Ohana/src/libfits/extern/gzip.c	(revision 38553)
+++ trunk/Ohana/src/libfits/extern/gzip.c	(revision 38986)
@@ -215,4 +215,8 @@
   err = inflate(&stream, Z_FINISH);
   if (err != Z_STREAM_END) {
+    if (err == Z_DATA_ERROR) {
+      fprintf (stderr, "compressed data is corrupted\n");
+      ESCAPE(err);
+    }
     inflateEnd(&stream);
     if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) ESCAPE (Z_DATA_ERROR);
Index: trunk/Ohana/src/libfits/header/F_H_field.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_H_field.c	(revision 38553)
+++ trunk/Ohana/src/libfits/header/F_H_field.c	(revision 38986)
@@ -33,5 +33,5 @@
   }
 
-  if (N < 0) {
+  if (N <= 0) {
     /* count the entries */
     Nfound = 0;
Index: trunk/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- trunk/Ohana/src/libfits/include/gfitsio.h	(revision 38553)
+++ trunk/Ohana/src/libfits/include/gfitsio.h	(revision 38986)
@@ -237,5 +237,5 @@
 int   	gfits_fread_ftable             PROTO((FILE *f, FTable *ftable, char *extname)); 
 int   	gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable, int padIfShort));
-int   	gfits_fread_ftable_range       PROTO((FILE *f, int padIfShort, FTable *ftable, off_t start, off_t Nrows));
+int   	gfits_fread_ftable_range       PROTO((FILE *f, int padIfShort, int noSeek, FTable *ftable, off_t start, off_t Nrows));
 int   	gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, off_t Nrow, off_t *row));
 int   	gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, off_t start, off_t Nrows));
Index: trunk/Ohana/src/libfits/matrix/F_compress_data.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_compress_data.c	(revision 38553)
+++ trunk/Ohana/src/libfits/matrix/F_compress_data.c	(revision 38986)
@@ -119,4 +119,8 @@
       return (FALSE);
     }
+    if (Nout > *Nzdata) {
+      fprintf (stderr, "buffer overrun! %d out, %d available\n", Nout, *Nzdata);
+      return FALSE;
+    }
     *Nzdata = Nout;
     return TRUE;
Index: trunk/Ohana/src/libfits/table/F_compress_T.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_compress_T.c	(revision 38553)
+++ trunk/Ohana/src/libfits/table/F_compress_T.c	(revision 38986)
@@ -211,5 +211,5 @@
 
   // allocate the intermediate storage buffers
-  int Nzdata_alloc = max_width*ztilelen + 100;
+  int Nzdata_alloc = 2*max_width*ztilelen + 100;
   ALLOCATE (raw,   char, max_width*ztilelen);
   ALLOCATE (zdata, char, Nzdata_alloc);
@@ -223,4 +223,6 @@
   gettimeofday (&startTimer, (void *) NULL);
 
+  // ohana_memcheck (TRUE);
+
   // compress the data : copy into a tile, compress the tile, then add to the output table
   // each tile -> 1 row of the output table
@@ -243,4 +245,6 @@
       }
       
+      // ohana_memcheck (TRUE);
+
       // XXX TIMER 2a
       gettimeofday (&stopTimer, (void *) NULL); 
@@ -260,4 +264,5 @@
       }
 
+      // ohana_memcheck (TRUE);
       // optname, optvalue = NULL, Noptions = 0
       
Index: trunk/Ohana/src/libfits/table/F_read_T.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_read_T.c	(revision 38553)
+++ trunk/Ohana/src/libfits/table/F_read_T.c	(revision 38986)
@@ -62,5 +62,5 @@
 
 /*********************** fits read ftable data ***********************************/
-int gfits_fread_ftable_range (FILE *f, int padIfShort, FTable *table, off_t start, off_t Nrows) {
+int gfits_fread_ftable_range (FILE *f, int padIfShort, int noSeek, FTable *table, off_t start, off_t Nrows) {
 
   off_t Nbytes, Nread, Nskip, Nx, Ny;
@@ -79,7 +79,16 @@
   Nskip = start * Nx;
   Nbytes = Nrows * Nx;
-  ALLOCATE (table[0].buffer, char, MAX (Nbytes, 1));
-
-  fseeko (f, Nskip, SEEK_CUR);
+
+  if (table[0].buffer) {
+    if (table[0].datasize < Nbytes) {
+      REALLOCATE (table[0].buffer, char, MAX (Nbytes, 1));
+    }
+  } else {
+    ALLOCATE (table[0].buffer, char, MAX (Nbytes, 1));
+  }
+
+  if (!noSeek) {
+    fseeko (f, Nskip, SEEK_CUR);
+  }
 
   Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
Index: trunk/Ohana/src/libfits/test/tcomptiming.c
===================================================================
--- trunk/Ohana/src/libfits/test/tcomptiming.c	(revision 38553)
+++ trunk/Ohana/src/libfits/test/tcomptiming.c	(revision 38986)
@@ -25,5 +25,5 @@
     int Ntile = pow (10.0, lNtile);
     fprintf (stderr, "--- Ntile = %d ---\n", Ntile);
-    test_compress_timing ("NONE_2", Ntile);
+    test_compress_timing ("GZIP_2", Ntile);
     gfits_compress_timing();
     gfits_uncompress_timing();
