libutils/Unicode.cpp: Correct length computation and add checks for utf16->utf8

Inconsistent behaviour between utf16_to_utf8 and utf16_to_utf8_length
is causing a heap overflow.

Correcting the length computation and adding bound checks to the
conversion functions.

Test: ran libutils_tests
Bug: 29250543
Change-Id: I6115e3357141ed245c63c6eb25fc0fd0a9a7a2bb
(cherry picked from commit c4966a363e46d2e1074d1a365e232af0dcedd6a1)

int strzcmp16_h_n(const char16_t *s1H, size_t n1, const char16_t *s2N, size_t n2)
{
 const char16_t* e1 = s1H+n1;
 const char16_t* e2 = s2N+n2;

 while (s1H < e1 && s2N < e2) {
 const char16_t c2 = ntohs(*s2N);
 const int d = (int)*s1H++ - (int)c2;
        s2N++;
 if (d) {
 return d;
 }
 }

 return n1 < n2
 ? (0 - (int)ntohs(*s2N))
 : (n1 > n2
 ? ((int)*s1H - 0)

            : 0);
 }

int strzcmp16_h_n(const char16_t *s1H, size_t n1, const char16_t *s2N, size_t n2)
{
 const char16_t* e1 = s1H+n1;
 const char16_t* e2 = s2N+n2;

 while (s1H < e1 && s2N < e2) {
 const char16_t c2 = ntohs(*s2N);
 const int d = (int)*s1H++ - (int)c2;
        s2N++;
 if (d) {
 return d;
 }
 }

 return n1 < n2
 ? (0 - (int)ntohs(*s2N))
 : (n1 > n2
 ? ((int)*s1H - 0)

            : 0);
 }
