+ /* Reallocate the buffer. Beware: The allocated size may be zero while the
+ * length is not. This means that we have a buffer that wasn't allocated
+ * on the heap.
+ */
+ if (B->Allocated) {
+ /* Just reallocate the block */
+ B->Buf = xrealloc (B->Buf, NewAllocated);
+ } else {
+ /* Allocate a new block and copy */
+ B->Buf = memcpy (xmalloc (NewAllocated), B->Buf, B->Len);
+ }
+
+ /* Remember the new block size */
+ B->Allocated = NewAllocated;
+}
+
+
+
+static void SB_CheapRealloc (StrBuf* B, unsigned NewSize)
+/* Reallocate the string buffer space, make sure at least NewSize bytes are
+ * available. This function won't copy the old buffer contents over to the new
+ * buffer and may be used if the old contents are overwritten later.
+ */
+{
+ /* Get the current size, use a minimum of 8 bytes */
+ unsigned NewAllocated = B->Allocated;
+ if (NewAllocated == 0) {
+ NewAllocated = 8;
+ }
+
+ /* Round up to the next power of two */
+ while (NewAllocated < NewSize) {
+ NewAllocated *= 2;
+ }
+
+ /* Free the old buffer if there is one */
+ if (B->Allocated) {
+ xfree (B->Buf);
+ }
+
+ /* Allocate a fresh block */
+ B->Buf = xmalloc (NewAllocated);
+
+ /* Remember the new block size */