[Opensrf-commits] r1765 - in trunk: include/opensrf src/libopensrf (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Sep 3 08:34:43 EDT 2009


Author: scottmk
Date: 2009-09-03 08:34:42 -0400 (Thu, 03 Sep 2009)
New Revision: 1765

Modified:
   trunk/include/opensrf/utils.h
   trunk/src/libopensrf/utils.c
Log:
1. A minor streamlining of va_list_to_string(), to eliminate
a layer of copying.

2. Corrected some faulty comments for doxygen.


Modified: trunk/include/opensrf/utils.h
===================================================================
--- trunk/include/opensrf/utils.h	2009-08-31 17:17:28 UTC (rev 1764)
+++ trunk/include/opensrf/utils.h	2009-09-03 12:34:42 UTC (rev 1765)
@@ -46,8 +46,8 @@
 #include "md5.h"
 /**
 	@brief Macro version of safe_malloc()
-	@param Pointer to be updated to point to newly allocated memory
-	@param How many bytes to allocate
+	@param ptr Pointer to be updated to point to newly allocated memory
+	@param size How many bytes to allocate
 */
 #define OSRF_MALLOC(ptr, size) \
 	do {\
@@ -155,7 +155,7 @@
 
 /**
 	@brief Resolves to a const pointer to the string inside a growing_buffer
-	@param Pointer to a growing_buffier
+	@param x Pointer to a growing_buffier
 */
 #define OSRF_BUFFER_C_STR( x ) ((const char *) (x)->buf)
 

Modified: trunk/src/libopensrf/utils.c
===================================================================
--- trunk/src/libopensrf/utils.c	2009-08-31 17:17:28 UTC (rev 1764)
+++ trunk/src/libopensrf/utils.c	2009-09-03 12:34:42 UTC (rev 1765)
@@ -236,17 +236,15 @@
 	va_list a_copy;
 
 	va_copy(a_copy, args);
-
 	va_start(args, format);
-	len = va_list_size(format, args);
 
-	char buf[len];
-	osrf_clearbuf(buf, sizeof(buf));
+	char* buf = safe_malloc( va_list_size(format, args) );
+	*buf = '\0';
 
 	va_start(a_copy, format);
 	vsnprintf(buf, len - 1, format, a_copy);
 	va_end(a_copy);
-	return strdup(buf);
+	return buf;
 }
 
 // ---------------------------------------------------------------------------------
@@ -286,6 +284,7 @@
 /**
 	@brief Allocate more memory for a growing_buffer.
 	@param gb A pointer to the growing_buffer.
+	@param total_len How much total memory we need for the buffer.
 	@return 0 if successful, or 1 if not.
 
 	This function fails if it is asked to allocate BUFFER_MAX_SIZE
@@ -477,7 +476,7 @@
 /**
 	@brief Remove the last character from a growing_buffer.
 	@param gb A pointer to the growing_buffer.
-	@return The character removed (or '\0' if the string is already empty).
+	@return The character removed (or a nul byte if the string is already empty).
 */
 char buffer_chomp(growing_buffer* gb) {
 	char c = '\0';
@@ -496,7 +495,7 @@
 	@param c The character to be appended.
 	@return The length of the resulting string.
 
-	If the character appended is a nul byte (i.e. '\0') it will still be appended as if
+	If the character appended is a nul byte it will still be appended as if
 	it were a normal character.  The results are likely to be unpleasant.
 */
 int buffer_add_char(growing_buffer* gb, char c ) {



More information about the opensrf-commits mailing list