aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mm-charsets.c5
-rw-r--r--src/mm-charsets.h2
-rw-r--r--src/tests/test-charsets.c11
3 files changed, 8 insertions, 10 deletions
diff --git a/src/mm-charsets.c b/src/mm-charsets.c
index d2b9a667..dd1ae087 100644
--- a/src/mm-charsets.c
+++ b/src/mm-charsets.c
@@ -427,14 +427,13 @@ mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len)
guint8 *
gsm_unpack (const guint8 *gsm,
- guint32 gsm_len,
+ guint32 nchars,
guint8 start_offset, /* in _bits_ */
guint32 *out_unpacked_len)
{
GByteArray *unpacked;
- int i, nchars;
+ int i;
- nchars = ((gsm_len * 8) - start_offset) / 7;
unpacked = g_byte_array_sized_new (nchars + 1);
for (i = 0; i < nchars; i++) {
diff --git a/src/mm-charsets.h b/src/mm-charsets.h
index 661052da..efd89f3c 100644
--- a/src/mm-charsets.h
+++ b/src/mm-charsets.h
@@ -53,7 +53,7 @@ guint8 *mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len);
guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, guint32 len);
guint8 *gsm_unpack (const guint8 *gsm,
- guint32 gsm_len,
+ guint32 nchars, /* number of gsm characters, not octets */
guint8 start_offset, /* in bits */
guint32 *out_unpacked_len);
diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c
index 656b80ca..70c796ab 100644
--- a/src/tests/test-charsets.c
+++ b/src/tests/test-charsets.c
@@ -98,7 +98,7 @@ test_unpack_gsm7 (void *f, gpointer d)
guint8 *unpacked;
guint32 unpacked_len = 0;
- unpacked = gsm_unpack (gsm, sizeof (gsm), 0, &unpacked_len);
+ unpacked = gsm_unpack (gsm, (sizeof (gsm) * 8) / 7, 0, &unpacked_len);
g_assert (unpacked);
g_assert_cmpint (unpacked_len, ==, sizeof (expected));
g_assert_cmpint (memcmp (unpacked, expected, unpacked_len), ==, 0);
@@ -110,17 +110,16 @@ static void
test_unpack_gsm7_7_chars (void *f, gpointer d)
{
static const guint8 gsm[] = { 0xF1, 0x7B, 0x59, 0x4E, 0xCF, 0xD7, 0x01 };
- static const guint8 expected[] = { 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x00 };
+ static const guint8 expected[] = { 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75};
guint8 *unpacked;
guint32 unpacked_len = 0;
/* Tests the edge case where there are 7 bits left in the packed
* buffer but those 7 bits do not contain a character. In this case
- * we expect a trailing NULL byte and the caller must know enough about
- * the intended message to remove it when required.
+ * we expect to get the number of characters that were specified.
*/
- unpacked = gsm_unpack (gsm, sizeof (gsm), 0, &unpacked_len);
+ unpacked = gsm_unpack (gsm, 7 , 0, &unpacked_len);
g_assert (unpacked);
g_assert_cmpint (unpacked_len, ==, sizeof (expected));
g_assert_cmpint (memcmp (unpacked, expected, unpacked_len), ==, 0);
@@ -153,7 +152,7 @@ test_unpack_gsm7_all_chars (void *f, gpointer d)
guint32 unpacked_len = 0;
int i;
- unpacked = gsm_unpack (gsm, sizeof (gsm), 0, &unpacked_len);
+ unpacked = gsm_unpack (gsm, (sizeof (gsm) * 8) / 7, 0, &unpacked_len);
g_assert (unpacked);
g_assert_cmpint (unpacked_len, ==, 148);