Index: /trunk/Ohana/src/libohana/Makefile
===================================================================
--- /trunk/Ohana/src/libohana/Makefile	(revision 39392)
+++ /trunk/Ohana/src/libohana/Makefile	(revision 39393)
@@ -66,6 +66,6 @@
 $(DESTLIB)/libohana.$(DLLTYPE): $(LIB)/libohana.$(ARCH).$(DLLTYPE)
 
-TESTPROG_XTRA = sprintf_floats
-TESTPROG = memtest typetest string 
+TESTPROG_XTRA = sprintf_floats memtest typetest string 
+TESTPROG = aliasing
 
 $(TESTPROG) : % : $(TESTBIN)/% $(OBJS)
Index: /trunk/Ohana/src/libohana/src/CommOps.c
===================================================================
--- /trunk/Ohana/src/libohana/src/CommOps.c	(revision 39392)
+++ /trunk/Ohana/src/libohana/src/CommOps.c	(revision 39393)
@@ -209,5 +209,5 @@
 
   if (buffer[0].Nbuffer < 16) return NULL;
-  memcpy (command, buffer[0].buffer, 16);
+  memcpy (command, buffer[0].buffer, 16); // SAFE
   command[16] = 0;
 
@@ -217,5 +217,5 @@
 
   ALLOCATE (line, char, Nbytes + 1);
-  memcpy (line, &buffer[0].buffer[16], Nbytes);
+  memcpy (line, &buffer[0].buffer[16], Nbytes); // SAFE
   line[Nbytes] = 0;
 
Index: /trunk/Ohana/src/libohana/src/config.c
===================================================================
--- /trunk/Ohana/src/libohana/src/config.c	(revision 39392)
+++ /trunk/Ohana/src/libohana/src/config.c	(revision 39393)
@@ -2,4 +2,5 @@
 
 # define D_NBYTES 4096
+# define NXTRA 16
 
 static char *ConfigVariable = (char *) NULL;
@@ -107,19 +108,4 @@
   }
   free (find);
-
-  /* we eliminate this option: this is just confusing */
-# if (0)  
-  /* look for ./.prognamerc */
-  sprintf (find, ".%src", progname);
-  status = stat (find, &filestat);
-  if (status == 0) { 
-    /* file exists, can we read it? */
-    if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR)) ||
-	((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP)) || 
-	(                            (filestat.st_mode & S_IROTH))) {
-      return (find);
-    }
-  }
-# endif
 
   /* look for ~/.prognamerc */
@@ -158,6 +144,6 @@
   Nbytes = 0;
   NBYTES = D_NBYTES;
-  ALLOCATE (ibuffer, char, NBYTES + 2);
-  memset (ibuffer, 0, NBYTES + 2);
+  ALLOCATE (ibuffer, char, NBYTES + NXTRA);
+  memset (ibuffer, 0, NBYTES + NXTRA);
     
   /* load data from file */
@@ -166,5 +152,5 @@
       Nbytes += nbytes;
       NBYTES += D_NBYTES;
-      REALLOCATE (ibuffer, char, NBYTES + 2);
+      REALLOCATE (ibuffer, char, NBYTES + NXTRA);
     }
     Nbytes += nbytes;
@@ -178,4 +164,5 @@
   }
   if (ibuffer[Nbytes]) ibuffer[Nbytes] = 0;
+  myAssert (Nbytes < NBYTES, "oops");
 
   /* add the optional variables to the end of the input buffer */
@@ -183,5 +170,5 @@
     snprintf (line, 256, "%s %s\n", "CONFIG", ConfigVariable);
     Ncpy = strlen (line);
-    if (Nbytes + Ncpy >= NBYTES - 1) {
+    if (Nbytes + Ncpy >= NBYTES - NXTRA) {
       NBYTES = Nbytes + Ncpy + D_NBYTES;
       REALLOCATE (ibuffer, char, NBYTES);
@@ -194,5 +181,5 @@
     snprintf (line, 256, "%s %s\n", DefineVariable[i], DefineValue[i]);
     Ncpy = strlen (line);
-    if (Nbytes + Ncpy >= NBYTES - 1) {
+    if (Nbytes + Ncpy >= NBYTES - NXTRA) {
       NBYTES = Nbytes + Ncpy + D_NBYTES;
       REALLOCATE (ibuffer, char, NBYTES);
@@ -202,4 +189,5 @@
     ibuffer[Nbytes] = 0;
   }
+  myAssert (Nbytes < NBYTES, "oops");
   
   /* loop over input buffer, interpolating 'input' lines until none are added */
@@ -218,5 +206,5 @@
       /* copy data from last point to before 'input' */ 
       Ncpy = next - last - 5;
-      if (Nout + Ncpy >= NBYTES - 1) {
+      if (Nout + Ncpy >= NBYTES - NXTRA) {
 	NBYTES = Nout + Ncpy + D_NBYTES;
 	REALLOCATE (obuffer, char, NBYTES);
@@ -230,5 +218,5 @@
       if (tbuffer != (char *) NULL) {
 	Ncpy = strlen (tbuffer);
-	if (Nout + Ncpy >= NBYTES - 1) {
+	if (Nout + Ncpy >= NBYTES - NXTRA) {
 	  NBYTES = Nout + Ncpy + D_NBYTES;
 	  REALLOCATE (obuffer, char, NBYTES);
@@ -248,5 +236,5 @@
     /* last set of bytes after last input */
     Ncpy = strlen (last);
-    if (Nout + Ncpy >= NBYTES - 1) {
+    if (Nout + Ncpy >= NBYTES - NXTRA) {
       NBYTES = Nout + Ncpy + D_NBYTES;
       REALLOCATE (obuffer, char, NBYTES);
@@ -277,5 +265,5 @@
   va_start (argp, Nentry);
 
-  int Nchar = strlen (field) + 16;
+  int Nchar = strlen (field) + NXTRA;
   ALLOCATE (tfield, char, Nchar);
   snprintf (tfield, Nchar, "\n%s", field);
@@ -341,12 +329,12 @@
 }
 
-
 char *expandline (char *line, char *config) {
 
-  int Nin, Nout, Ncpy, NBYTES;
+  int Nin, Nout, Ncpy;
   char *p1, *p2, word[256], value[256];
   char *outline;
   
-  NBYTES = 256;
+  int DBYTES = 256;
+  int NBYTES = 256;
   ALLOCATE (outline, char, NBYTES);
   Nout = 0;
@@ -354,7 +342,7 @@
   while ((p1 = strchr (&line[Nin], '$')) != (char *) NULL) {
     Ncpy = p1 - line - Nin;
-    if (Nout + Ncpy >= NBYTES) {
-      NBYTES = Nout + Ncpy + 256;
-      REALLOCATE (outline, char, NBYTES - 2);
+    if (Nout + Ncpy >= NBYTES - NXTRA) {
+      NBYTES = Nout + Ncpy + DBYTES;
+      REALLOCATE (outline, char, NBYTES);
     }
     memcpy (&outline[Nout], &line[Nin], Ncpy);
@@ -373,6 +361,6 @@
     }
     Ncpy = strlen(value);
-    if (Nout + Ncpy >= NBYTES - 2) {
-      NBYTES = Nout + Ncpy + 256;
+    if (Nout + Ncpy >= NBYTES - NXTRA) {
+      NBYTES = Nout + Ncpy + DBYTES;
       REALLOCATE (outline, char, NBYTES);
     }    
@@ -381,6 +369,6 @@
   }
   Ncpy = strlen(&line[Nin]);
-  if (Nout + Ncpy >= NBYTES - 2) {
-    NBYTES = Nout + Ncpy + 256;
+  if (Nout + Ncpy >= NBYTES - NXTRA) {
+    NBYTES = Nout + Ncpy + DBYTES;
     REALLOCATE (outline, char, NBYTES);
   }  
@@ -409,5 +397,5 @@
   Nbytes = 0;
   NBYTES = D_NBYTES;
-  ALLOCATE_ZERO (ibuffer, char, NBYTES + 2);
+  ALLOCATE_ZERO (ibuffer, char, NBYTES + NXTRA);
 
   /* load data from file */
@@ -415,6 +403,6 @@
     Nbytes += nbytes;
     NBYTES += D_NBYTES;
-    REALLOCATE (ibuffer, char, NBYTES + 2);
-    memset (&ibuffer[NBYTES - D_NBYTES], 0, NBYTES - D_NBYTES + 2);
+    REALLOCATE (ibuffer, char, NBYTES + NXTRA);
+    memset (&ibuffer[NBYTES - D_NBYTES], 0, NBYTES - D_NBYTES);
   }
   Nbytes += nbytes;
@@ -427,4 +415,5 @@
   }
   if (ibuffer[Nbytes]) ibuffer[Nbytes] = 0;
+  myAssert (Nbytes < NBYTES, "oops");
 
   if (options) {
@@ -433,9 +422,9 @@
       snprintf (line, 256, "%s %s\n", "CONFIG", ConfigVariable);
       Ncpy = strlen (line);
-      if (Nbytes + Ncpy >= NBYTES) {
+      if (Nbytes + Ncpy >= NBYTES - NXTRA) {
 	int Nbytes_old = NBYTES;
 	NBYTES = Nbytes + Ncpy + D_NBYTES;
-	REALLOCATE (ibuffer, char, NBYTES + 2);
-	memset (&ibuffer[Nbytes_old], 0, NBYTES + 2 - Nbytes_old);
+	REALLOCATE (ibuffer, char, NBYTES + NXTRA);
+	memset (&ibuffer[Nbytes_old], 0, NBYTES - Nbytes_old);
       }    
       memcpy (&ibuffer[Nbytes], line, Ncpy);
@@ -446,9 +435,9 @@
       snprintf (line, 256, "%s %s\n", DefineVariable[i], DefineValue[i]);
       Ncpy = strlen (line);
-      if (Nbytes + Ncpy >= NBYTES) {
+      if (Nbytes + Ncpy >= NBYTES - NXTRA) {
 	int Nbytes_old = NBYTES;
 	NBYTES = Nbytes + Ncpy + D_NBYTES;
-	REALLOCATE (ibuffer, char, NBYTES + 2);
-	memset (&ibuffer[Nbytes_old], 0, NBYTES + 2 - Nbytes_old);
+	REALLOCATE (ibuffer, char, NBYTES + NXTRA);
+	memset (&ibuffer[Nbytes_old], 0, NBYTES - Nbytes_old);
       }    
       memcpy (&ibuffer[Nbytes], line, Ncpy);
Index: /trunk/Ohana/src/libohana/src/findexec.c
===================================================================
--- /trunk/Ohana/src/libohana/src/findexec.c	(revision 39392)
+++ /trunk/Ohana/src/libohana/src/findexec.c	(revision 39393)
@@ -75,4 +75,7 @@
   int status;
   int valid;
+
+  myAssert (basefile, "oops");
+  myAssert (basefile[0], "oops");
 
   uid = getuid();
@@ -152,4 +155,6 @@
   char *c, *file;
 
+  myAssert (strlen(infile), "invalid zero-length infile");
+
   /* make working version */
   file = strcreate (infile);
@@ -238,5 +243,5 @@
   char *c, *file;
 
-  ALLOCATE (file, char, strlen(name) + 1);
+  ALLOCATE (file, char, strlen(name) + 16);
 
   c = strrchr (name, '/');
Index: /trunk/Ohana/src/libohana/src/glockfile.c
===================================================================
--- /trunk/Ohana/src/libohana/src/glockfile.c	(revision 39392)
+++ /trunk/Ohana/src/libohana/src/glockfile.c	(revision 39393)
@@ -4,5 +4,5 @@
   
   int status;
-  char mode[3];
+  char mode[16];
   int fd;
   FILE *f;
Index: /trunk/Ohana/src/libohana/src/ohana_allocate.c
===================================================================
--- /trunk/Ohana/src/libohana/src/ohana_allocate.c	(revision 39392)
+++ /trunk/Ohana/src/libohana/src/ohana_allocate.c	(revision 39393)
@@ -5,4 +5,5 @@
 # include <pthread.h>
 # include <string.h>
+# include <errno.h>
 
 # define TEST_SAVE_FREE_BLOCKS 0
@@ -53,6 +54,7 @@
 
   // total size is : memblock + data + endpost
-  new = (OhanaMemblock *) malloc (sizeof(OhanaMemblock) + size + sizeof(void *)); 
+  new = (OhanaMemblock *) malloc (sizeof(OhanaMemblock) + size + 2*sizeof(void *)); 
   if (new == NULL) ohana_memabort ("failed to allocate memory (%s, %d, %s)\n", file, line, func);
+  if (errno == ENOMEM) abort();
 
   // pointer to the start of the user memory
@@ -71,6 +73,6 @@
   new->freed = FALSE;
 
-  // to be clean, zero out the memory
-  // memset (ptr, 0, new->size);
+  // poison the whole memory: we should not rely of 0'ed memory
+  memset (ptr, 0x7f, new->size);
 
   // new memblock becomes the 'lastBlock':
@@ -98,4 +100,6 @@
   Nblock ++;
   pthread_mutex_unlock(&memBlockListMutex);
+
+  if (!new->nextBlock && !new->prevBlock && (Nblock > 1)) abort();
 
   return (ptr);
@@ -219,7 +223,11 @@
 
   ref = (OhanaMemblock *) in - 1;
+  if (!ref->nextBlock && !ref->prevBlock && (Nblock > 1)) ohana_memabort ("orphan block?? (%s@%d : %s)\n", file, line, func);
 
   if (ref->freed) ohana_memabort ("memory already freed (%s, %d, %s [%d bytes])\n", ref->file, ref->line, ref->func, ref->size);
+  // if (!ref->nextBlock && !ref->prevBlock && (Nblock > 1)) ohana_memabort ("orphan block?? (%s@%d : %s)\n", file, line, func);
+
   ref->freed = TRUE;
+  if (!ref->nextBlock && !ref->prevBlock && (Nblock > 1)) ohana_memabort ("orphan block?? (%s@%d : %s)\n", file, line, func);
 
   // fprintf (stderr, "  file: %s, line: %d, func: %s, size: %zd, addr: %zx\n", 
@@ -227,4 +235,5 @@
 
   if (!lastBlock) ohana_memabort ("corruption? (%s@%d : %s)\n", file, line, func);
+  if (!ref->nextBlock && !ref->prevBlock && (Nblock > 1)) ohana_memabort ("orphan block?? (%s@%d : %s)\n", file, line, func);
 
   pthread_mutex_lock(&memBlockListMutex);
@@ -260,5 +269,5 @@
   // pointer to the start of the user memory
   void *ptr = (char *)(ref + 1);
-  memset (ptr, 0x77, ref->size);
+  memset (ptr, 0x7f, ref->size);
 
   Nblock --;
@@ -268,4 +277,5 @@
   
 # if (!TEST_SAVE_FREE_BLOCKS)
+  memset (ref, 0x7f, sizeof(OhanaMemblock));
   free (ref);
 # endif
Index: /trunk/Ohana/src/libohana/src/string.c
===================================================================
--- /trunk/Ohana/src/libohana/src/string.c	(revision 39392)
+++ /trunk/Ohana/src/libohana/src/string.c	(revision 39393)
@@ -186,5 +186,5 @@
     line[i] = c;
   }
-  line[i - 1] = 0;  /* this could make things crash! */
+  if (i > 0) line[i - 1] = 0;  /* this could make things crash! */
 
   if (i > 1) {
