Index: branches/eam_branches/ipp-20101205/Ohana/src/libdvo/src/dvo_util.c
===================================================================
--- branches/eam_branches/ipp-20101205/Ohana/src/libdvo/src/dvo_util.c	(revision 30443)
+++ branches/eam_branches/ipp-20101205/Ohana/src/libdvo/src/dvo_util.c	(revision 30448)
@@ -255,4 +255,5 @@
       dvo_catalog_free (&catalog);
   }
+  size_t NInvalidDetID = 0;
   if (Ndetect) {
       dvoDetection *sorted;
@@ -262,5 +263,9 @@
       off_t i;
       for (i = 0; i < Ndetect; i++) {
-           sorted[detections[i].meas.detID] = detections[i];
+
+          if (detections[i].meas.detID < 0 || detections[i].meas.detID > (*pMaxDetID + 1))
+              NInvalidDetID++;
+          else
+              sorted[detections[i].meas.detID] = detections[i];
       }
       *results = sorted;
@@ -271,4 +276,6 @@
   FREE(detections);
 
+  if (NInvalidDetID) fprintf (stderr, "ERROR: Encountered %ld invalid detection IDs\n", NInvalidDetID);
+
   return (Ndetect);
 
Index: branches/eam_branches/ipp-20101205/Ohana/src/tools/src/roc.c
===================================================================
--- branches/eam_branches/ipp-20101205/Ohana/src/tools/src/roc.c	(revision 30443)
+++ branches/eam_branches/ipp-20101205/Ohana/src/tools/src/roc.c	(revision 30448)
@@ -33,10 +33,11 @@
 
   usage();
-  exit (1);
+  exit (2);
 }
 
 int roc_create (int argc, char **argv) {
 
-  int i, j, n, Ninput, result, Nblocks, header_size, size_off, Noff, Nbytes, Nread;
+  int i, j, n, Ninput, result, Nblocks, header_size, size_off;
+  int status, Noff, Nbytes, Nread, Nwrite;
   off_t maxSize, *sizes, *bytes_read;
   char value;
@@ -124,5 +125,6 @@
   myAssert (target, "failed to open output");
 
-  fwrite (header, 1, header_size, target);
+  Nwrite = fwrite (header, 1, header_size, target);
+  myAssert (Nwrite == header_size, "failed to write header");
 
   ALLOCATE (inputData, char *, Ninput);
@@ -137,4 +139,5 @@
       Nbytes = fread (inputData[i], 1, Nread, input[i]);
       myAssert (Nbytes == Nread, "failed to read data");
+
       if (Nread < ROC_BLOCKSIZE) {
 	// if we have reached the end of the file, fill in the rest with NULLs
@@ -152,6 +155,10 @@
     }
 
-    fwrite (outputData, 1, ROC_BLOCKSIZE, target);
-  }
+    Nwrite = fwrite (outputData, 1, ROC_BLOCKSIZE, target);
+    myAssert (Nwrite == ROC_BLOCKSIZE, "failed to write data block");
+  }
+
+  status = fclose (target);
+  myAssert (!status, "failed to close rocfile");
 
   exit (0);
@@ -160,5 +167,6 @@
 int roc_repair (int argc, char **argv) {
 
-  int i, j, n, Ninput, Nblocks, header_size, Nbytes, Nread, Nfile, Nwrite;
+  int i, j, n, Ninput, Nblocks, header_size, Nbytes;
+  int status, Nread, Nfile, Nwrite;
   off_t *sizes, *bytes_read;
   char value;
@@ -204,5 +212,6 @@
   // read the full header
   fseeko (target, 0, SEEK_SET);
-  fread (header, 1, header_size, target);
+  Nread = fread (header, 1, header_size, target);
+  myAssert (Nread == header_size, "failed to read header");
 
   ptr = header;
@@ -255,4 +264,5 @@
       Nbytes = fread (inputData[i], 1, Nread, input[i]);
       myAssert (Nbytes == Nread, "failed to read data");
+
       if (Nread < ROC_BLOCKSIZE) {
 	// if we have reached the end of the file, fill in the rest with NULLs
@@ -261,5 +271,6 @@
       bytes_read[i] += Nread;
     }
-    fread (targetData, 1, ROC_BLOCKSIZE, target);
+    Nread = fread (targetData, 1, ROC_BLOCKSIZE, target);
+    myAssert (Nread == ROC_BLOCKSIZE, "failed to read from target");
     
     for (j = 0; j < ROC_BLOCKSIZE; j++) {
@@ -281,8 +292,12 @@
   for (i = 0; i < Ninput; i++) {
     if (i == Nfile) continue;
-    fclose(input[i]);
-  }
-  fclose (output);
-  fclose (target);
+    status = fclose(input[i]);
+    myAssert (!status, "failed to close input");
+  }
+  status = fclose (output);
+  myAssert (!status, "failed to close output file");
+
+  status = fclose (target);
+  myAssert (!status, "failed to close rocfile");
 
   exit (0);
