#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 {\
/**
@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)
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;
}
// ---------------------------------------------------------------------------------
/**
@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
/**
@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';
@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 ) {