rem: if (len > sizeof(buf)-1) exit_cleanup(RERR_MESSAGEIO);
add: if (len > sizeof(buf)-1  ||  len < 0) { const char ellipsis[] = "[...]";   len = sizeof(buf)-1; buf[len] = '\0';   strncpy(buf+len-sizeof(ellipsis), ellipsis, sizeof(ellipsis)); if (format[strlen(format)-1] == '\n') { buf[len-1] = '\n'; } }
context: void rprintf(enum logcode code, const char *format, ...){	va_list ap;  	char buf[1024];	int len;	va_start(ap, format);	len = vsnprintf(buf, sizeof(buf), format, ap);	va_end(ap);	if (len > sizeof(buf)-1) exit_cleanup(RERR_MESSAGEIO);	rwrite(code, buf, len);}