Index: trunk/psLib/src/collections/psBitSet.c
===================================================================
--- trunk/psLib/src/collections/psBitSet.c	(revision 578)
+++ trunk/psLib/src/collections/psBitSet.c	(revision 614)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-05 20:43:22 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-08 00:08:27 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -55,20 +55,4 @@
 /*****************************************************************************/
 
-/** Private function to return a byte.
- *
- *  Finds the byte containing the bit within the byte array.
- *
- *  @return  char*: Pointer to byte in which bit is contained.
- */
-static char* getByte(int bit, const psBitSet *restrict inMask)
-{
-    int index = 0;
-    char *byte = 0;
-    index = bit/8;
-    byte = inMask->bits+index;
-
-    return byte;
-}
-
 /** Private function to create a mask.
  *
@@ -80,5 +64,7 @@
 static char mask(int bit)
 {
-    char mask = 0x01;
+    char mask = (char)0x01;
+    // Ignore splint warning about negative bit shifts
+    /*@i@*/
     mask = mask << (bit%8);
 
@@ -91,6 +77,16 @@
 psBitSet* psBitSetAlloc(int n)
 {
-    psBitSet *newObj = psAlloc(sizeof(psBitSet));
+    psBitSet *newObj = NULL;
+
+    if(n <= 0) {
+        psError(__func__, " : Line %d - Allocation size must be >= 0: size = %d\n", __LINE__, n);
+        return 0;
+    }
+
+    newObj = psAlloc(sizeof(psBitSet));
     newObj->n = n;
+
+    // Ignore splint warning about releasing pointer members, since they've not been allocated yet
+    /*@i@*/
     newObj->bits = psAlloc(sizeof(char)*n);
     memset(newObj->bits, n, 0);
@@ -101,4 +97,8 @@
 void psBitSetFree(psBitSet *restrict inBitSet)
 {
+    if(inBitSet == NULL) {
+        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__);
+        return;
+    }
     psFree(inBitSet->bits);
     psFree(inBitSet);
@@ -107,5 +107,16 @@
 psBitSet* psBitSetSet(psBitSet *inBitSet, int bit)
 {
-    char* byte = getByte(bit, inBitSet);
+    char* byte = NULL;
+
+    if(inBitSet == NULL) {
+        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__);
+        return inBitSet;
+    } else if(bit < 0) {
+        psError(__func__, " : Line %d - Negative bit position not allowed: %d\n", __LINE__, bit);
+        return inBitSet;
+    }
+
+    // Variable byte is the byte in the array that contains the bit to be set
+    byte = inBitSet->bits+bit/8;
     *byte |= mask(bit);
 
@@ -115,6 +126,17 @@
 int psBitSetTest(const psBitSet *inBitSet, int bit)
 {
-    char* byte = getByte(bit, inBitSet);
-    if((*byte&mask(bit)) == 0) {
+    char* byte = NULL;
+
+    if(inBitSet == NULL) {
+        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__);
+        return 0;
+    } else if(bit < 0) {
+        psError(__func__, " : Line %d - Negative bit position not allowed: %d\n", __LINE__, bit);
+        return 0;
+    }
+
+    // Variable byte is the byte in the array that contains the bit to be tested
+    byte = inBitSet->bits+bit/8;
+    if((int)(*byte&mask(bit)) == 0) {
         return 0;
     }
@@ -191,7 +213,7 @@
     int i = 0;
     int numBits = inBitSet->n*8;
-    char* outString = psAlloc(numBits);
+    char* outString = psAlloc((size_t)numBits);
     for(i=0; i<numBits; i++) {
-        outString[numBits-i-1] = (psBitSetTest(inBitSet, i))?'1':'0';
+        outString[numBits-i-1] = (psBitSetTest(inBitSet, i) == 1)?'1':'0';
     }
 
