last = p + (bufsz - 1);
while (p && *p && p <= last) {
- if (*p == '\\' || iscntrl((unsigned char) *p)) {
+ if ((p < last && *p == '\\' && *(p + 1) == 'x')
+ || iscntrl((unsigned char) *p)) {
width += 4, bytes += 4; /* *p encoded to \x?? */
p++;
}
continue;
}
- if (*p == '\\' || iscntrl((unsigned char) *p)) {
+ if ((*p == '\\' && *(p + 1) == 'x')
+ || iscntrl((unsigned char) *p)) {
sprintf(r, "\\x%02x", (unsigned char) *p);
r += 4;
*width += 4;
(*width)++;
*r++ = *p;
}
+ } else if (*p == '\\' && *(p + 1) == 'x') {
+ sprintf(r, "\\x%02x", (unsigned char) *p);
+ r += 4;
+ *width += 4;
} else {
memcpy(r, p, len);
r += len;