Fix PrintableString() for 4-byte UTF-8 sequences.

Test: Additional test in utf_test.
Bug: 128865240
Change-Id: I535e028319393abb17ee258086e47593f80f4ed3
diff --git a/libdexfile/dex/utf.cc b/libdexfile/dex/utf.cc
index ed07568..3eb80b1 100644
--- a/libdexfile/dex/utf.cc
+++ b/libdexfile/dex/utf.cc
@@ -283,10 +283,10 @@
   return result;
 }
 
-std::string PrintableString(const char* utf) {
+std::string PrintableString(const char* utf8) {
   std::string result;
   result += '"';
-  const char* p = utf;
+  const char* p = utf8;
   size_t char_count = CountModifiedUtf8Chars(p);
   for (size_t i = 0; i < char_count; ++i) {
     uint32_t ch = GetUtf16FromUtf8(&p);
@@ -311,6 +311,9 @@
       if (trailing != 0) {
         // All high surrogates will need escaping.
         StringAppendF(&result, "\\u%04x", trailing);
+        // Account for the surrogate pair.
+        ++i;
+        DCHECK_LT(i, char_count);
       }
     }
   }