util: Use ell in convert_utf8_to_gsm

This commit is contained in:
Denis Kenzior 2018-12-21 12:35:06 -06:00
parent c4b073aa89
commit 5229080d92
3 changed files with 21 additions and 25 deletions

View File

@ -557,13 +557,13 @@ gboolean sms_encode_address_field(const struct sms_address *in, gboolean sc,
return FALSE; return FALSE;
if (written > 11) { if (written > 11) {
g_free(gsm); l_free(gsm);
return FALSE; return FALSE;
} }
r = pack_7bit_own_buf(gsm, written, 0, false, &packed, 0, p); r = pack_7bit_own_buf(gsm, written, 0, false, &packed, 0, p);
g_free(gsm); l_free(gsm);
if (r == NULL) if (r == NULL)
return FALSE; return FALSE;
@ -3633,7 +3633,7 @@ GSList *sms_text_prepare_with_alphabet(const char *to, const char *utf8,
pack_7bit_own_buf(gsm_encoded, written, offset, false, NULL, pack_7bit_own_buf(gsm_encoded, written, offset, false, NULL,
0, template.submit.ud + offset); 0, template.submit.ud + offset);
g_free(gsm_encoded); l_free(gsm_encoded);
return sms_list_append(NULL, &template); return sms_list_append(NULL, &template);
} }
@ -4767,12 +4767,12 @@ gboolean ussd_encode(const char *str, long *items_written, unsigned char *pdu)
converted = convert_utf8_to_gsm(str, -1, NULL, &written, 0); converted = convert_utf8_to_gsm(str, -1, NULL, &written, 0);
if (converted == NULL || written > 182) { if (converted == NULL || written > 182) {
g_free(converted); l_free(converted);
return FALSE; return FALSE;
} }
pack_7bit_own_buf(converted, written, 0, true, &num_packed, 0, pdu); pack_7bit_own_buf(converted, written, 0, true, &num_packed, 0, pdu);
g_free(converted); l_free(converted);
if (num_packed < 1) if (num_packed < 1)
return FALSE; return FALSE;

View File

@ -4037,13 +4037,13 @@ static gboolean stk_tlv_builder_append_gsm_packed(struct stk_tlv_builder *iter,
return FALSE; return FALSE;
if (iter->len + (written * 7 + 7) / 8 >= iter->max_len) { if (iter->len + (written * 7 + 7) / 8 >= iter->max_len) {
g_free(gsm); l_free(gsm);
return FALSE; return FALSE;
} }
pack_7bit_own_buf(gsm, len, 0, false, &written, 0, pack_7bit_own_buf(gsm, len, 0, false, &written, 0,
iter->value + iter->len + 1); iter->value + iter->len + 1);
g_free(gsm); l_free(gsm);
if (written < 1 && len > 0) if (written < 1 && len > 0)
return FALSE; return FALSE;
@ -4072,7 +4072,7 @@ static gboolean stk_tlv_builder_append_gsm_unpacked(
return FALSE; return FALSE;
if (iter->len + written >= iter->max_len) { if (iter->len + written >= iter->max_len) {
g_free(gsm); l_free(gsm);
return FALSE; return FALSE;
} }
@ -4080,7 +4080,7 @@ static gboolean stk_tlv_builder_append_gsm_unpacked(
memcpy(iter->value + iter->len, gsm, written); memcpy(iter->value + iter->len, gsm, written);
iter->len += written; iter->len += written;
g_free(gsm); l_free(gsm);
return TRUE; return TRUE;
} }

View File

@ -3042,18 +3042,18 @@ unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len,
res_len = 0; res_len = 0;
while ((len < 0 || text + len - in > 0) && *in) { while ((len < 0 || text + len - in > 0) && *in) {
long max = len < 0 ? 6 : text + len - in; long max = len < 0 ? 4 : text + len - in;
gunichar c = g_utf8_get_char_validated(in, max); wchar_t c;
unsigned short converted = GUND; unsigned short converted;
int nread = l_utf8_get_codepoint(in, max, &c);
if (c & 0x80000000) if (nread < 0)
goto err_out; goto err_out;
if (c > 0xffff) if (c > 0xffff)
goto err_out; goto err_out;
converted = unicode_locking_shift_lookup(&t, c); converted = unicode_locking_shift_lookup(&t, c);
if (converted == GUND) if (converted == GUND)
converted = unicode_single_shift_lookup(&t, c); converted = unicode_single_shift_lookup(&t, c);
@ -3065,23 +3065,20 @@ unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len,
else else
res_len += 1; res_len += 1;
in = g_utf8_next_char(in); in += nread;
nchars += 1; nchars += 1;
} }
res = g_try_malloc(res_len + (terminator ? 1 : 0)); res = l_malloc(res_len + (terminator ? 1 : 0));
if (res == NULL)
goto err_out;
in = text; in = text;
out = res; out = res;
for (i = 0; i < nchars; i++) {
unsigned short converted;
gunichar c = g_utf8_get_char(in); for (i = 0; i < nchars; i++) {
wchar_t c;
unsigned short converted;
int nread = l_utf8_get_codepoint(in, 4, &c);
converted = unicode_locking_shift_lookup(&t, c); converted = unicode_locking_shift_lookup(&t, c);
if (converted == GUND) if (converted == GUND)
converted = unicode_single_shift_lookup(&t, c); converted = unicode_single_shift_lookup(&t, c);
@ -3092,8 +3089,7 @@ unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len,
*out = converted; *out = converted;
++out; ++out;
in += nread;
in = g_utf8_next_char(in);
} }
if (terminator) if (terminator)