Author: julianfoad
Date: Tue Apr  3 15:03:56 2012
New Revision: 1308966

URL: http://svn.apache.org/viewvc?rev=1308966&view=rev
Log:
Make svn_stringbuf_ensure() allocate an additional byte for the null
terminator, bringing it in line with svn_stringbuf_create_ensure() which
always had those semantics.  Some callers had been expecting this behaviour,
and thus had been buggy.  This will make buggy callers just work, and any
callers that were already adding one byte will still work whether they get
updated or not.  It would now be an error to link code written against the
new API to a library containing an old implementation of the function.

* subversion/include/svn_string.h
  (svn_stringbuf_ensure): Promise to allocate space for the null.

* subversion/libsvn_subr/svn_string.c
  (svn_stringbuf_ensure): Add one to the requested minimum size.

Modified:
    subversion/trunk/subversion/include/svn_string.h
    subversion/trunk/subversion/libsvn_subr/svn_string.c

Modified: subversion/trunk/subversion/include/svn_string.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_string.h?rev=1308966&r1=1308965&r2=1308966&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_string.h (original)
+++ subversion/trunk/subversion/include/svn_string.h Tue Apr  3 15:03:56 2012
@@ -235,10 +235,12 @@ svn_stringbuf_t *
 svn_stringbuf_createv(apr_pool_t *pool, const char *fmt, va_list ap)
   __attribute__((format(printf, 2, 0)));
 
-/** Make sure that the string @a str has at least @a minimum_size bytes of
- * space available in the memory block.
+/** Make sure that the string @a str has allocated at least enough space
+ * to hold a string of length @a minimum_size bytes (as well as the
+ * terminating null character).
  *
- * (@a minimum_size should include space for the terminating NULL character.)
+ * @note: Before Subversion 1.8, the caller was supposed to include one
+ * byte for the null terminator in the value of @a minimum_size.
  */
 void
 svn_stringbuf_ensure(svn_stringbuf_t *str, apr_size_t minimum_size);

Modified: subversion/trunk/subversion/libsvn_subr/svn_string.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/svn_string.c?rev=1308966&r1=1308965&r2=1308966&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/svn_string.c (original)
+++ subversion/trunk/subversion/libsvn_subr/svn_string.c Tue Apr  3 15:03:56 
2012
@@ -441,6 +441,8 @@ svn_stringbuf_isempty(const svn_stringbu
 void
 svn_stringbuf_ensure(svn_stringbuf_t *str, apr_size_t minimum_size)
 {
+  ++minimum_size;  /* + space for '\0' */
+
   /* Keep doubling capacity until have enough. */
   if (str->blocksize < minimum_size)
     {


Reply via email to