[svn-commits] russell: branch russell/ast_verbose_threadstorage r38544 - /team/russell/ast_...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Jul 30 20:45:02 MST 2006


Author: russell
Date: Sun Jul 30 22:45:02 2006
New Revision: 38544

URL: http://svn.digium.com/view/asterisk?rev=38544&view=rev
Log:
add more code comments

Modified:
    team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h

Modified: team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h?rev=38544&r1=38543&r2=38544&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h Sun Jul 30 22:45:02 2006
@@ -256,7 +256,7 @@
 	({                                                                       \
 		int __res;                                                       \
 		while ((__res = __ast_dynamic_str_thread_printf_va(buf, max_len, \
-			ts, fmt, ap)) == AST_DYNSTR_PRINTF_RETRY) {               \
+			ts, fmt, ap)) == AST_DYNSTR_PRINTF_RETRY) {              \
 			va_end(ap);                                              \
 			va_start(ap, fmt);                                       \
 		}                                                                \
@@ -276,16 +276,28 @@
 	int res;
 
 	res = vsnprintf((*buf)->str, (*buf)->len, fmt, ap);
-	
+
+	/* Check to see if there was not enough space in the string buffer to prepare
+	 * the string.  Also, if a maximum length is present, make sure the current
+	 * length is less than the maximum before increasing the size. */
 	if ((res + 1) > (*buf)->len && (max_len ? ((*buf)->len < max_len) : 1)) {
+		/* Set the new size of the string buffer to be the size needed
+		 * to hold the resulting string (res) plus one byte for the
+		 * terminating '\0'.  If this size is greater than the max, set
+		 * the new length to be the maximum allowed. */
 		if (max_len)
 			(*buf)->len = ((res + 1) < max_len) ? (res + 1) : max_len;
 		else
 			(*buf)->len = res + 1;
+
 		if (!(*buf = ast_realloc(*buf, (*buf)->len + sizeof(*(*buf)))))
 			return AST_DYNSTR_PRINTF_FAILED;
+
 		if (ts)
 			pthread_setspecific(ts->key, *buf);
+
+		/* va_end() and va_start() must be done before calling
+		 * vsnprintf() again. */
 		return AST_DYNSTR_PRINTF_RETRY;
 	}
 



More information about the svn-commits mailing list