Index: /branches/eam_branches/ohana.20170809/src/libfits/header/F_H_field.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/header/F_H_field.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/header/F_H_field.c	(revision 40113)
@@ -104,4 +104,5 @@
       ptr = buf + 9; // start of following keyword
       if (strncmp (field, ptr, Nfield)) continue;
+      if (ptr[Nfield + 1] != '=') continue; // the strncmp above will match a longer string which matches the subset of field (e.g., FOO will match FOOBAR and FOO).  test for the following '=' sign
       Nfound ++;
     }
@@ -116,4 +117,5 @@
       ptr = buf + 9; // start of following keyword
       if (strncmp (field, ptr, Nfield)) continue;
+      if (ptr[Nfield + 1] != '=') continue; // the strncmp above will match a longer string which matches the subset of field (e.g., FOO will match FOOBAR and FOO).  test for the following '=' sign
       Nfound ++;
       if (Nwant == Nfound) return (ptr);
Index: /branches/eam_branches/ohana.20170809/src/libfits/header/F_create_H.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/header/F_create_H.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/header/F_create_H.c	(revision 40113)
@@ -1,5 +1,4 @@
 # include <ohana.h>
 # include <gfitsio.h>
-# define NBYTES 2880
 
 /******************** fits create header ***********************************/
@@ -9,10 +8,11 @@
   char axis[10];
   
-  header[0].datasize = NBYTES;
+  header[0].datasize = FT_RECORD_SIZE;
 
-  ALLOCATE (header[0].buffer, char, NBYTES);
+  ALLOCATE (header[0].buffer, char, FT_RECORD_SIZE);
 
-  for (i = 0; i < NBYTES; i++) 
-    header[0].buffer[i] = ' ';
+  // XXX this is just slightly suspicious : I am not ending the buffer with a NULL.  if I
+  // use any string operations on it then they can run past the end.
+  for (i = 0; i < FT_RECORD_SIZE; i++) header[0].buffer[i] = ' ';
   strncpy (header[0].buffer, "END", 3);
 
Index: /branches/eam_branches/ohana.20170809/src/libfits/header/F_modify.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/header/F_modify.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/header/F_modify.c	(revision 40113)
@@ -72,5 +72,5 @@
     char *ptr = va_arg (argp, char *);
     if (!ptr) goto invalid;
-    strncpy (data, ptr, 68);
+    strncpy (data, ptr, 68); data[68] = 0;
     snprintf (string, 81, "%-8s= '%-8s' / %-s ", field, data, comment);
     goto found_it;
@@ -119,4 +119,5 @@
       header[0].datasize += FT_RECORD_SIZE;
       REALLOCATE (header[0].buffer, char, header[0].datasize);
+      /* re-find the "END" marker, in case new memory block is used */
       p = gfits_header_field (header, "END", 1);
       if (p == NULL) return (FALSE); 
@@ -138,8 +139,11 @@
   /* write the boolean mode */
   if (!strcmp (mode, "%t")) {
-    if (va_arg (argp, int)) 
-      snprintf (string, 81, "%-8s= %18s T / %-s ", field, " ", comment);
-    else
-      snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment);
+    // fill data will spaces, null terminated, so snprintf can generate a space-filled block
+    memset (data, ' ', FT_LINE_LENGTH); data[FT_LINE_LENGTH] = 0;
+    if (va_arg (argp, int))  {
+      snprintf (string, 81, "%-8s= %18s T / %-s ", field, data, comment);
+    } else {
+      snprintf (string, 81, "%-8s= %18s F / %-s ", field, data, comment);
+    }
   }
 
@@ -148,5 +152,5 @@
     char *ptr = va_arg (argp, char *);
     if (!ptr) goto invalid;
-    strncpy (data, ptr, 71);
+    strncpy (data, ptr, 71); data[71] = 0;
     snprintf (string, 81, "%-8s %-71s", field, data);
   }  
@@ -159,5 +163,7 @@
     /* keep ' on ends, if there */
     if (qe[0]  == 0x27) qe ++;
-    if (qs[-1] == 0x27) qs --;
+    if (qs >= p + 1) { 
+      if (qs[-1] == 0x27) qs --;
+    }
 
     strncpy (data, qs, MAX (MIN (qe - qs, 71), 0));
Index: /branches/eam_branches/ohana.20170809/src/libfits/header/F_print.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/header/F_print.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/header/F_print.c	(revision 40113)
@@ -7,6 +7,5 @@
   /* this function expects one more argument, the value to be written */
 
-  static char blank[] = " ";
-  char string[82], line[80];
+  char string[82], line[82], blank[82];
   char *p;
   va_list argp;  
@@ -41,4 +40,6 @@
   memset (p, ' ', FT_LINE_LENGTH);
 
+  memset (blank, ' ', FT_LINE_LENGTH); blank[FT_LINE_LENGTH] = 0;
+
   /* write the new FITS card, setting the comment to be blank */
   /* in these lines, the value field will expand as needed, forcing out the comment
@@ -67,6 +68,5 @@
     char *ptr = va_arg (argp, char *);
     if (!ptr) goto invalid;
-    strcpy (line, ptr);
-    line[68] = 0;
+    strncpy (line, ptr, 68); line[68] = 0;
     snprintf (string, 81, "%-8s= '%-8s' / %46s ", field, line, blank);
     goto found_it;
@@ -88,10 +88,12 @@
   /* this function expects one more argument, the value to be written */
 
-  static char blank[] = " ";
-  char string[82], line[80];
-  char *p, a;
+  char string[82], line[82], blank[82];
+  char *p;
   va_list argp;  
 
   va_start (argp, N);
+  bzero (line, 82);
+  bzero (string, 82);
+  bzero (blank, 82);
   
   if (mode[0] != '%') {
@@ -122,11 +124,14 @@
   memset (p, ' ', FT_LINE_LENGTH);
 
+  memset (blank, ' ', FT_LINE_LENGTH); blank[FT_LINE_LENGTH] = 0;
+
   /* write the boolean mode */
   if (!strcmp (mode, "%t")) {
-    a = va_arg (argp, int);
-    if (a == 1)
+    int a = va_arg (argp, int);
+    if (a == 1) {
       snprintf (string, 81, "%-8s= %18s T / %46s ", field, blank, blank);
-    else
+    } else {
       snprintf (string, 81, "%-8s= %18s F / %46s ", field, blank, blank);
+    }
   }
 
Index: /branches/eam_branches/ohana.20170809/src/libfits/header/F_scan.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/header/F_scan.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/header/F_scan.c	(revision 40113)
@@ -89,5 +89,5 @@
   // XXX is this safe for 64bit off_t and 32bit off_t?
   // XXX the problem is that we read FITS files on many machine types: I need to ensure 
-  // that we are portable -- this sseems inconsistent
+  // that we are portable -- this seems inconsistent
   if (!strcmp (mode, "%jd"))  { *va_arg (argp, intmax_t *) 	     = value; return (TRUE); }
 
@@ -168,5 +168,5 @@
   /* all others require '=' in column p + 1 + strlen(field) */
   Nfield = strlen (field);
-  if (p[Nfield + 1] != '=') return (FALSE);
+  if (p[Nfield + 1] != '=') return (FALSE); // probably redundant since gfits_header_hierarch_field requires this condition
 
   /* comment from data line */
Index: /branches/eam_branches/ohana.20170809/src/libfits/matrix/F_compress_utils.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/matrix/F_compress_utils.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/matrix/F_compress_utils.c	(revision 40113)
@@ -136,5 +136,5 @@
 
     int has_extension, has_extname, has_zimage, zimage;
-    char extname[80], extension[80];
+    char extname[82], extension[82];
 
     has_extension = gfits_scan (header, "XTENSION", "%s", 1, extension);
Index: /branches/eam_branches/ohana.20170809/src/libfits/matrix/F_uncompress_data.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/matrix/F_uncompress_data.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/matrix/F_uncompress_data.c	(revision 40113)
@@ -6,4 +6,6 @@
 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); }
 
+// *Nout comes in with the number of expected (uncompressed) bytes
+// *Nout returns the number uncompressed pixels
 int gfits_uncompress_data (char *zdata, unsigned long Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, unsigned long int *Nout, unsigned long int Nout_alloc, int out_pixsize) {
 
Index: /branches/eam_branches/ohana.20170809/src/libfits/table/F_create_T.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/table/F_create_T.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/table/F_create_T.c	(revision 40113)
@@ -43,4 +43,5 @@
   }
   table[0].datasize = Nbytes;
+  table[0].validsize = Nbytes;
   table[0].heap_start = gfits_heap_start (header);
   return (TRUE);
@@ -58,4 +59,5 @@
     bzero (table[0].buffer, Nbytes);
     table[0].datasize = Nbytes;
+    table[0].validsize = Nbytes;
     table[0].heap_start = gfits_heap_start (header);
   return (TRUE);
Index: /branches/eam_branches/ohana.20170809/src/libfits/table/F_create_TH.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/table/F_create_TH.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/table/F_create_TH.c	(revision 40113)
@@ -1,5 +1,4 @@
 # include <ohana.h>
 # include <gfitsio.h>
-# define NBYTES 2880
 
 /* a basic table header (extension) is different from a primary header
@@ -13,11 +12,10 @@
   char axis[128];
   
-  header[0].datasize = NBYTES;
+  header[0].datasize = FT_RECORD_SIZE;
 
   myAssert (!header->buffer, "failed to init header or free buffer?");
-  ALLOCATE (header[0].buffer, char, NBYTES);
+  ALLOCATE (header[0].buffer, char, FT_RECORD_SIZE);
   
-  for (i = 0; i < NBYTES; i++) 
-  header[0].buffer[i] = ' ';
+  for (i = 0; i < FT_RECORD_SIZE; i++) header[0].buffer[i] = ' ';
   strncpy (header[0].buffer, "END", 3);
   
Index: /branches/eam_branches/ohana.20170809/src/libfits/table/F_define_column.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/table/F_define_column.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/table/F_define_column.c	(revision 40113)
@@ -56,5 +56,5 @@
   char type[64], field[64];
   
-  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
+  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE); // *** FUNC : OK
   
   Nfields = 0;
Index: /branches/eam_branches/ohana.20170809/src/libfits/table/F_set_column.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/table/F_set_column.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/table/F_set_column.c	(revision 40113)
@@ -1,6 +1,6 @@
 # include <ohana.h>
 # include <gfitsio.h>
-# define OHANA_MEMCHECK 0
-# define CHECK_MEMBLOCKS 0
+# define OHANA_MEMCHECK 1
+# define CHECK_MEMBLOCKS 1
 
 # define SWAP_NONE 
@@ -33,5 +33,5 @@
   int Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[256], field[256], format[256], type[64], tmpline[64];
-  char *Pin, *Pout, *array;
+  char *Pin, *Pout;
   double Bscale, Bzero;
 
@@ -53,4 +53,6 @@
 # endif
 
+  // fprintf (stderr, "Pin: 0x%08lx, Pout: 0x%08lx, array: 0x%08lx\n", (long int) &Pin, (long int) &Pout, (long int) &array);
+
   if (label == (char *) NULL) return (FALSE);
   if (label[0] == 0) return (FALSE);
@@ -67,4 +69,5 @@
 
   /* interpret format */
+# if (0)
   snprintf (field, 256, "TSCAL%d", N);
   if (!gfits_scan (header, field, "%lf", 1, &Bscale)) {
@@ -75,4 +78,9 @@
     Bzero = 0.0;
   }
+# else
+    Bscale = 1.0;
+    Bzero = 0.0;
+# endif  
+
   snprintf (field, 256, "TFORM%d", N);
   if (!gfits_scan (header, field, "%s", 1, format)) return FALSE;
@@ -107,9 +115,10 @@
   /* make duplicate of data with correct type
      byte swap and Bzero/Bscale */
-  ALLOCATE (array, char, Nbytes*Nval*Nrow);
+  ALLOCATE_PTR (array, char, Nbytes*Nval*Nrow);
   if (CHECK_MEMBLOCKS) {
     OhanaMemblock *ref = (OhanaMemblock *) array - 1;
-    fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
+    // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
     if (!ref->nextBlock && !ref->prevBlock) abort();
+    if (!ref->size) abort();
   }
 
@@ -121,5 +130,5 @@
   if (CHECK_MEMBLOCKS) {
     OhanaMemblock *ref = (OhanaMemblock *) array - 1;
-    fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
+    // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
     if (!ref->nextBlock && !ref->prevBlock) abort();
   }
@@ -213,5 +222,5 @@
   if (CHECK_MEMBLOCKS) {
     OhanaMemblock *ref = (OhanaMemblock *) array - 1;
-    fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
+    // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
     if (!ref->nextBlock && !ref->prevBlock) abort();
   }
@@ -242,5 +251,5 @@
   if (CHECK_MEMBLOCKS) {
     OhanaMemblock *ref = (OhanaMemblock *) array - 1;
-    fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
+    // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
     if (!ref->nextBlock && !ref->prevBlock) abort();
   }
Index: /branches/eam_branches/ohana.20170809/src/libfits/table/F_table_format.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/table/F_table_format.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/table/F_table_format.c	(revision 40113)
@@ -3,5 +3,5 @@
 
 /***********************/
-// get the format of a table column
+// get the format of a table column (see comment block below)
 // Nval : number of joined columns
 // Nbytes : width of column
@@ -86,5 +86,9 @@
    
    all can be preceeded by integer N which specified number
-   of entries in array
+   of entries in array:
+
+   1L == L
+   2L
+   3E, etc
 */
 
Index: /branches/eam_branches/ohana.20170809/src/libfits/table/F_uncompress_T.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/libfits/table/F_uncompress_T.c	(revision 40112)
+++ /branches/eam_branches/ohana.20170809/src/libfits/table/F_uncompress_T.c	(revision 40113)
@@ -267,5 +267,9 @@
       unsigned long int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen;
       unsigned long int Nraw = Nrows*fields[i].Nvalues*fields[i].pixsize; // expected number of bytes
+      unsigned long int Npix_expect = Nrows*fields[i].Nvalues; // expected number of pixels
+
+      myAssert (Nraw <= Nraw_alloc, "bad size");
       if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, Nraw_alloc, fields[i].pixsize)) ESCAPE;
+      myAssert (Npix_expect == Nraw, "bad size");
 
       if (VERBOSE_DUMP) {
