libcsdbg  1.28
C++ exception (and generic) stack trace debug library
i8 * csdbg::util::va_format ( const i8 fmt,
va_list  args 
)
static

Format a buffer with a printf-style string expanded with the values of a variable argument list.

Parameters
[in]fmta printf-style format string
[in]argsa variable argument list (as a va_list variable)
Returns
the formatted string (heap allocated)
Exceptions
std::bad_alloc
csdbg::exception

Definition at line 519 of file util.cpp.

References unlikely, and va_size().

Referenced by dbg(), csdbg::exception::exception(), csdbg::string::format(), and va_format().

520 {
521  if ( unlikely(fmt == NULL) ) {
522  va_end(args);
523  throw exception("invalid argument: fmt (=%p)", fmt);
524  }
525 
526  va_list cpargs;
527  va_copy(cpargs, args);
528  i8 *retval = NULL;
529 
530  try {
531  i32 sz = va_size(fmt, cpargs);
532  retval = new i8[sz + 1];
533 
534  i32 check = vsprintf(retval, fmt, args);
535  if ( unlikely(check != sz) )
536  throw exception("vsprintf failed with retval %d", check);
537 
538  va_end(args);
539  return retval;
540  }
541 
542  catch (...) {
543  delete[] retval;
544  va_end(args);
545  throw;
546  }
547 }
char i8
8-bit signed integer
Definition: config.hpp:72
int i32
32-bit signed integer
Definition: config.hpp:82
static i32 va_size(const i8 *, va_list)
Compute the size of a printf-style format string expanded with the values of a variable argument list...
Definition: util.cpp:489
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349

+ Here is the call graph for this function:

+ Here is the caller graph for this function: