Index: trunk/psLib/src/collections/psList.c
===================================================================
--- trunk/psLib/src/collections/psList.c	(revision 2681)
+++ trunk/psLib/src/collections/psList.c	(revision 2694)
@@ -6,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-10 02:50:14 $
+ *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-10 21:43:16 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -74,5 +74,5 @@
 static psBool listIteratorRemove(psListIterator* iterator)
 {
-    if (iterator == NULL) {
+    if (iterator == NULL || iterator->cursor == NULL) {
         return false;
     }
@@ -102,5 +102,5 @@
         if (iter->cursor == elem) {
             iter->cursor = NULL;
-        } else if (iter->index > index) {
+        } else if (iter->index > index && iter->index > 0) {
             iter->index--;
         }
@@ -183,5 +183,5 @@
     psList* list = iterator->list;
 
-    if (location >= list->size) {
+    if (location >= (int)list->size) {
         psLogMsg(__func__, PS_LOG_WARN,
                  "Specified index, %d, is beyond the end of the psList, which "
@@ -283,6 +283,7 @@
 
     psListElem* cursor = iterator->cursor;
-
-    if (cursor == NULL) {
+    psList* list = iterator->list;
+
+    if (cursor == NULL && list->head != NULL) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 PS_ERRORTEXT_psList_ITERATOR_INVALID);
@@ -290,5 +291,4 @@
     }
 
-    psList* list = iterator->list;
     psListElem* elem = psAlloc(sizeof(psListElem));
 
@@ -297,9 +297,20 @@
 
     // set the new list element's attributes
-    elem->prev = cursor;
-    elem->next = cursor->next;
-    elem->data = data;
-
-    cursor->next = elem;
+    if (cursor == NULL) { // must be an empty list
+        elem->prev = NULL;
+        elem->next = NULL;
+        list->head = elem;
+        list->tail = elem;
+    } else {
+        elem->prev = cursor;
+        elem->next = cursor->next;
+        cursor->next = elem;
+        if (elem->next == NULL) {
+            list->tail = elem;
+        }
+    }
+
+    elem->data = psMemIncrRefCounter(data);
+
     list->size++;
 
@@ -338,6 +349,7 @@
 
     psListElem* cursor = iterator->cursor;
-
-    if (cursor == NULL) {
+    psList* list = iterator->list;
+
+    if (cursor == NULL && list->head != NULL) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 PS_ERRORTEXT_psList_ITERATOR_INVALID);
@@ -345,5 +357,4 @@
     }
 
-    psList* list = iterator->list;
     psListElem* elem = psAlloc(sizeof(psListElem));
 
@@ -352,9 +363,20 @@
 
     // set the new list element's attributes
-    elem->prev = cursor->prev;
-    elem->next = cursor;
-    elem->data = data;
-
-    cursor->prev = elem;
+    if (cursor == NULL) { // empty list.
+        elem->prev = NULL;
+        elem->next = NULL;
+        list->head = elem;
+        list->tail = elem;
+    } else {
+        elem->prev = cursor->prev;
+        elem->next = cursor;
+        cursor->prev = elem;
+        if (elem->prev == NULL) {
+            list->head = elem;
+        }
+    }
+
+    elem->data = psMemIncrRefCounter(data);
+
     list->size++;
 
@@ -435,4 +457,10 @@
 psPtr psListGet(psList* list, psS32 location)
 {
+    if (list == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                PS_ERRORTEXT_psList_LIST_NULL);
+        return false;
+    }
+
     psListIterator* iterator = list->iterators->data[0];
 
