diff --git a/minidlnatypes.h b/minidlnatypes.h index bda1959..addb754 100644 --- a/minidlnatypes.h +++ b/minidlnatypes.h @@ -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; diff --git a/utils.c b/utils.c index c2cb5eb..57ae5a4 100644 --- a/utils.c +++ b/utils.c @@ -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;