]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Have memBufAppend \0 terminate the data, allowing it to be used on strings
authorhno <>
Tue, 16 Apr 2002 06:35:39 +0000 (06:35 +0000)
committerhno <>
Tue, 16 Apr 2002 06:35:39 +0000 (06:35 +0000)
(done quite frequently, the error was unnotices as mempools always zeroed
the data, and the likelyhood the buffer is exacly filled is very small)

src/MemBuf.cc

index 2e0780d8100f0b1ac0bbe7781f98fc16d094c82e..d78c8823e5950f406f32c5439da69d42b38ad7fc 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: MemBuf.cc,v 1.30 2002/04/13 23:07:48 hno Exp $
+ * $Id: MemBuf.cc,v 1.31 2002/04/16 00:35:39 hno Exp $
  *
  * DEBUG: section 59    auto-growing Memory Buffer with printf
  * AUTHOR: Alex Rousskov
@@ -190,11 +190,12 @@ memBufAppend(MemBuf * mb, const char *buf, mb_size_t sz)
     assert(!mb->stolen);       /* not frozen */
 
     if (sz > 0) {
-       if (mb->size + sz > mb->capacity)
-           memBufGrow(mb, mb->size + sz);
+       if (mb->size + sz + 1 > mb->capacity)
+           memBufGrow(mb, mb->size + sz + 1);
        assert(mb->size + sz <= mb->capacity);  /* paranoid */
        xmemcpy(mb->buf + mb->size, buf, sz);
        mb->size += sz;
+       mb->buf[mb->size] = '\0';       /* \0 terminate in case we are used as a string. Not counted in the size */
     }
 }