Index: trunk/src/core/RpSimpleBuffer.h
===================================================================
--- trunk/src/core/RpSimpleBuffer.h	(revision 2458)
+++ trunk/src/core/RpSimpleBuffer.h	(revision 2460)
@@ -214,5 +214,5 @@
     
     /// Minimum number of members is set to the number you can fit in 256 bytes
-    const static int _minNumElems=(256/sizeof(T));
+    const static size_t _minNumElems = (256/sizeof(T));
     
     size_t __guesslen(const T* bytes);
@@ -355,20 +355,12 @@
 template<class T>
 int
-SimpleBuffer<T>::append(const T* bytes, int nmemb)
-{
-    size_t newMembCnt = 0;
-
-    void* dest = NULL;
-    void const* src  = NULL;
-    size_t size = 0;
+SimpleBuffer<T>::append(const T* bytes, int numElems)
+{
 
     // User specified NULL buffer to append
-    if ( (bytes == NULL) && (nmemb < 1) ) {
-        return 0;
-    }
-
-#ifdef notdef
-
-    /* This is dead code.  The test above catches the condition. */
+    if (bytes == NULL) {
+        return 0;			// Should not give append a NULL
+					// buffer pointer.
+    }
 
     // FIXME: i think this needs to be division,
@@ -377,18 +369,128 @@
     // bytes in *bytes.
 
+    size_t numBytes = 0;
+    if (numElems == -1) {
+	/* This should be moved into the SimpleCharBuffer.  It doesn't make
+	 * sense to look for a NUL byte unless it's a string buffer. We
+	 * can then change numElems to be size_t. */
+        numBytes = __guesslen(bytes);
+        numElems = numBytes / sizeof(T);
+    }
+    if (numElems <= 0) {
+        return numElems;
+    }
+
+    size_t newSize;
+    newSize = _numElemsUsed + numElems;
+    if (newSize > _numElemsAllocated) {
+
+        // buffer sizes less than min_size are set to min_size
+        if (newSize < _minNumElems) {
+            newSize = _minNumElems;
+        }
+
+        /*
+         * Allocate a larger buffer for the string if the current one isn't
+         * large enough. Allocate extra space in the new buffer so that there
+         * will be room to grow before we have to allocate again.
+         */
+        size_t size;
+        size = (_numElemsAllocated > 0) ? _numElemsAllocated : _minNumElems;
+        while (newSize > size) {
+            size += size;
+        }
+
+        /*
+         * reallocate to a larger buffer
+         */
+        if (set(size) != size) {
+            return 0;
+        }
+    }
+    memcpy(_buf + _numElemsUsed, bytes, numElems * sizeof(T));
+    _numElemsUsed += numElems;
+    return numElems;
+}
+
+/**
+ * Append bytes to the end of this buffer
+ * @param pointer to bytes to be added
+ * @param number of bytes to be added
+ * @return number of bytes appended.
+ */
+template<class T>
+size_t
+SimpleBuffer<T>::extend(size_t numExtraElems)
+{
+    size_t newSize;
+
+    newSize = _numElemsUsed + numExtraElems;
+    if (newSize > _numElemsAllocated) {
+
+        /* Enforce a minimum buffer size. */
+        if (newSize < (size_t) _minNumElems) {
+            newSize = (size_t) _minNumElems;
+        }
+
+        size_t size;
+        size = (_numElemsAllocated > 0) ? _numElemsAllocated : _minNumElems;
+
+	/* Keep doubling the size of the buffer until we have enough space to
+	 * hold the extra elements. */
+        while (newSize > size) {
+            size += size;
+        }
+        /* Reallocate to a larger buffer. */
+        if (set(size) != size) {
+            return 0;
+        }
+    }
+    return _numElemsAllocated;
+}
+
+/**
+ * Append formatted bytes to the end of this buffer
+ * @param pointer to bytes to be added
+ * @param number of bytes to be added
+ * @return number of bytes appended.
+ */
+template<class T>
+int
+SimpleBuffer<T>::appendf(const char *format, ...)
+{
+    size_t newMembCnt = 0;
     size_t nbytes = 0;
-    if (nmemb == -1) {
-        // user signaled null terminated string
-        // or that we should make an educated guess
-        // at the length of the object.
-        nbytes = __guesslen(bytes);
-        nmemb = nbytes/sizeof(T);
-    }
-
-    if (nmemb <= 0) {
+    int nmemb = 0;
+
+    char* dest = NULL;
+    size_t size = 0;
+    size_t bytesAdded = 0;
+    va_list arg;
+
+    // User specified NULL format
+    if (format == NULL) {
+        return 0;
+    }
+
+    // FIXME: i think this needs to be division,
+    // need to create test case with array of ints
+    // i'm not sure we can even guess the number
+    // bytes in *bytes.
+
+
+    // add one for terminating null character
+    nbytes = strlen(format) + 1;
+
+    if (nbytes <= 0) {
         // no data written, invalid option
-        return nmemb;
-    }
-#endif
+        return nbytes;
+    }
+
+    // FIXME: we need ceil of nbytes/sizeof(T), instead we add 1 for safety
+
+    nmemb = nbytes/sizeof(T);
+    if (nmemb == 0) {
+        nmemb++;
+    }
 
     newMembCnt = (size_t)(_numElemsUsed + nmemb);
@@ -420,123 +522,4 @@
     }
 
-    dest = (void*) (_buf + _numElemsUsed);
-    src  = (void const*) bytes;
-    size = (size_t) (nmemb*sizeof(T));
-    memcpy(dest,src,size);
-
-    _numElemsUsed += nmemb;
-
-    return nmemb;
-}
-
-/**
- * Append bytes to the end of this buffer
- * @param pointer to bytes to be added
- * @param number of bytes to be added
- * @return number of bytes appended.
- */
-template<class T>
-size_t
-SimpleBuffer<T>::extend(size_t numExtraElems)
-{
-    size_t newSize;
-
-    newSize = _numElemsUsed + numExtraElems;
-    if (newSize > _numElemsAllocated) {
-
-        /* Enforce a minimum buffer size. */
-        if (newSize < (size_t) _minNumElems) {
-            newSize = (size_t) _minNumElems;
-        }
-
-        size_t size;
-        size = (_numElemsAllocated > 0) ? _numElemsAllocated : _minNumElems;
-
-	/* Keep doubling the size of the buffer until we have enough space to
-	 * hold the extra elements. */
-        while (newSize > size) {
-            size += size;
-        }
-        /* Reallocate to a larger buffer. */
-        if (set(size) != size) {
-            return 0;
-        }
-    }
-    return _numElemsAllocated;
-}
-
-/**
- * Append formatted bytes to the end of this buffer
- * @param pointer to bytes to be added
- * @param number of bytes to be added
- * @return number of bytes appended.
- */
-template<class T>
-int
-SimpleBuffer<T>::appendf(const char *format, ...)
-{
-    size_t newMembCnt = 0;
-    size_t nbytes = 0;
-    int nmemb = 0;
-
-    char* dest = NULL;
-    size_t size = 0;
-    size_t bytesAdded = 0;
-    va_list arg;
-
-    // User specified NULL format
-    if (format == NULL) {
-        return 0;
-    }
-
-    // FIXME: i think this needs to be division,
-    // need to create test case with array of ints
-    // i'm not sure we can even guess the number
-    // bytes in *bytes.
-
-
-    // add one for terminating null character
-    nbytes = strlen(format) + 1;
-
-    if (nbytes <= 0) {
-        // no data written, invalid option
-        return nbytes;
-    }
-
-    // FIXME: we need ceil of nbytes/sizeof(T), instead we add 1 for safety
-
-    nmemb = nbytes/sizeof(T);
-    if (nmemb == 0) {
-        nmemb++;
-    }
-
-    newMembCnt = (size_t)(_numElemsUsed + nmemb);
-
-    if (newMembCnt > _numElemsAllocated) {
-
-        // buffer sizes less than min_size are set to min_size
-        if (newMembCnt < (size_t) _minNumElems) {
-            newMembCnt = (size_t) _minNumElems;
-        }
-
-        /*
-         * Allocate a larger buffer for the string if the current one isn't
-         * large enough. Allocate extra space in the new buffer so that there
-         * will be room to grow before we have to allocate again.
-         */
-        size_t membAvl;
-        membAvl = (_numElemsAllocated > 0) ? _numElemsAllocated : _minNumElems;
-        while (newMembCnt > membAvl) {
-            membAvl += membAvl;
-        }
-
-        /*
-         * reallocate to a larger buffer
-         */
-        if (set(membAvl) != membAvl) {
-            return 0;
-        }
-    }
-
     dest = (char*) (_buf + _numElemsUsed);
     size = (_numElemsAllocated-_numElemsUsed)*sizeof(T);
