* ReAdjustEmptyBuf() wasn't quiet what it should be: increase the buffer to a specifi...
authorWilfried Göesgens <willi@citadel.org>
Fri, 21 May 2010 20:21:27 +0000 (20:21 +0000)
committerWilfried Göesgens <willi@citadel.org>
Fri, 21 May 2010 20:21:27 +0000 (20:21 +0000)
libcitadel/lib/stringbuf.c

index 97be33b15d06fb58a5d43001dcbeabf2555f40d6..523733a7ace6e54e63339d5baf655ca485a42fb8 100644 (file)
@@ -286,14 +286,16 @@ static int IncreaseBuf(StrBuf *Buf, int KeepOriginal, int DestSize)
 
 /**
  * @ingroup StrBuf_DeConstructors
- * @brief shrink an _EMPTY_ buffer if its Buffer superseeds threshhold to NewSize. Buffercontent is thoroughly ignored and flushed.
+ * @brief shrink / increase an _EMPTY_ buffer to NewSize. Buffercontent is thoroughly ignored and flushed.
  * @param Buf Buffer to shrink (has to be empty)
  * @param ThreshHold if the buffer is bigger then this, its readjusted
  * @param NewSize if we Shrink it, how big are we going to be afterwards?
  */
 void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize)
 {
-       if ((Buf != NULL) && (Buf->BufUsed > ThreshHold)) {
+       if ((Buf != NULL) && 
+           (Buf->BufUsed == 0) &&
+           (Buf->BufSize < ThreshHold)) {
                free(Buf->buf);
                Buf->buf = (char*) malloc(NewSize);
                Buf->BufUsed = 0;