From fc2ea7ffb17c1429a22109bf4fac9ccb64c054ba Mon Sep 17 00:00:00 2001 From: scottmk Date: Thu, 3 Sep 2009 12:34:42 +0000 Subject: [PATCH] 1. A minor streamlining of va_list_to_string(), to eliminate a layer of copying. 2. Corrected some faulty comments for doxygen. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1765 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/utils.h | 6 +++--- src/libopensrf/utils.c | 13 ++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/opensrf/utils.h b/include/opensrf/utils.h index c259b7d..b98920a 100644 --- a/include/opensrf/utils.h +++ b/include/opensrf/utils.h @@ -46,8 +46,8 @@ extern "C" { #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 @@ extern "C" { /** @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) diff --git a/src/libopensrf/utils.c b/src/libopensrf/utils.c index 358dd27..79e6d0f 100644 --- a/src/libopensrf/utils.c +++ b/src/libopensrf/utils.c @@ -236,17 +236,15 @@ char* va_list_to_string(const char* format, ...) { 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 @@ growing_buffer* buffer_init(int num_initial_bytes) { /** @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 @@ char* buffer_data( const growing_buffer *gb) { /** @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 @@ char buffer_chomp(growing_buffer* gb) { @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 ) { -- 2.43.2