- snprintf (buf, size, "%s%s", rs->prefix, rs->buf);
+ /*
+ * if this condition is not met, we lose data
+ * because the cached data does not fit into the buffer.
+ * this cannot happen if size is the same throughout all calls.
+ */
+ assert(strlen(rs->prefix) + strlen(rs->buf) + 1 <= (size_t)size);
+
+ if ((strlcpy(buf, rs->prefix, size) >= (size_t)size)
+ || (strlcat(buf, rs->buf, size) >= (size_t)size)) {
+ overrun(__FILE__, __LINE__);
+ }
+