- /*
- * String is too long, copy as much as possible.
- * It will be further truncated later.
- */
- memcpy(tempbuf, sval, sizeof(tempbuf)-1);
- tempbuf[sizeof(tempbuf)-1] = '\0';
- }
- else
- {
- memcpy(tempbuf, sval, (size_t) ival);
- tempbuf[ival] = '\0';
+ if (isprint((int)*sval) && (*sval != '\\'))
+ {
+ outbuf[length++] = *sval;
+ outbuf[length] = '\0';
+ }
+ else
+ {
+ snprintf(outbuf + length, log_buffer_size - length - 2,
+ "\\x%.2x", (int)*sval);
+ length += 4;
+ }
+ sval++;