- Check for output truncation in strcatf().

This commit is contained in:
Justin Maggard 2013-04-02 23:29:21 +00:00
parent 1c748c1d5a
commit ba75f275e1
2 changed files with 9 additions and 4 deletions

View File

@ -50,8 +50,8 @@ struct runtime_vars_s {
struct string_s {
char *data; // ptr to start of memory area
int off;
int size;
size_t off;
size_t size;
};
typedef uint8_t media_types;

View File

@ -37,11 +37,16 @@ inline int
strcatf(struct string_s *str, const char *fmt, ...)
{
int ret;
int size;
va_list ap;
if (str->off >= str->size)
return 0;
va_start(ap, fmt);
ret = vsnprintf(str->data + str->off, str->size - str->off, fmt, ap);
str->off += ret;
size = str->size - str->off;
ret = vsnprintf(str->data + str->off, size, fmt, ap);
str->off += MIN(ret, size);
va_end(ap);
return ret;