Re-instate commit c0fc2e881b

pull/10148/head
Jorg Brown 3 years ago
parent 24d0a3bed1
commit 7bb756c1cc
  1. 6
      src/google/protobuf/stubs/strutil.cc

@ -501,9 +501,11 @@ int CEscapeInternal(const char* src, int src_len, char* dest,
if ((!utf8_safe || static_cast<uint8_t>(*src) < 0x80) &&
(!isprint(*src) ||
(last_hex_escape && isxdigit(*src)))) {
if (dest_len - used < 4) // need space for 4 letter escape
// need space for 4 letter escape and the trailing '\0' to
// be written by snprintf.
if (dest_len - used < 5)
return -1;
sprintf(dest + used, (use_hex ? "\\x%02x" : "\\%03o"),
snprintf(dest + used, 5, (use_hex ? "\\x%02x" : "\\%03o"),
static_cast<uint8_t>(*src));
is_hex_escape = use_hex;
used += 4;

Loading…
Cancel
Save