diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-04-02 13:31:31 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-04-02 17:04:01 +0200 |
commit | 678f596ff996dd483d00f026cd21e120fbde698b (patch) | |
tree | c2fb1b1bd1621e6a22617b599f244174da0411b7 | |
parent | fc219be4d46aefe644cc17b6a0976be5c1a732b8 (diff) |
qcdm-serial-port: avoid playing with GByteArray internals
Since glib 2.32, we can use g_byte_array_new_take() to build a new GByteArray
from an own allocated buffer, so skip playing with the GByteArray internals.
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | src/mm-qcdm-serial-port.c | 17 |
2 files changed, 13 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac index d8c98a0c..ed4fd1a3 100644 --- a/configure.ac +++ b/configure.ac @@ -59,7 +59,7 @@ AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package]) PKG_CHECK_MODULES(MM, - glib-2.0 >= 2.30.2 + glib-2.0 >= 2.32 gmodule-2.0 gobject-2.0 gio-2.0 @@ -68,7 +68,7 @@ AC_SUBST(MM_CFLAGS) AC_SUBST(MM_LIBS) PKG_CHECK_MODULES(LIBMM_GLIB, - glib-2.0 >= 2.30.2 + glib-2.0 >= 2.32 gobject-2.0 gio-2.0 gio-unix-2.0) @@ -76,7 +76,7 @@ AC_SUBST(LIBMM_GLIB_CFLAGS) AC_SUBST(LIBMM_GLIB_LIBS) PKG_CHECK_MODULES(MMCLI, - glib-2.0 >= 2.30.2 + glib-2.0 >= 2.32 gobject-2.0 gio-2.0) AC_SUBST(MMCLI_CFLAGS) diff --git a/src/mm-qcdm-serial-port.c b/src/mm-qcdm-serial-port.c index 44a5f1c3..bce80519 100644 --- a/src/mm-qcdm-serial-port.c +++ b/src/mm-qcdm-serial-port.c @@ -81,6 +81,7 @@ handle_response (MMSerialPort *port, { MMQcdmSerialResponseFn response_callback = (MMQcdmSerialResponseFn) callback; GByteArray *unescaped = NULL; + guint8 *unescaped_buffer; GError *dm_error = NULL; gsize used = 0; gsize start = 0; @@ -101,11 +102,10 @@ handle_response (MMSerialPort *port, goto callback; } - /* FIXME: don't munge around with byte array internals */ - unescaped = g_byte_array_sized_new (1024); + unescaped_buffer = g_malloc (1024); success = dm_decapsulate_buffer ((const char *) (response->data + start), response->len - start, - (char *) unescaped->data, + (char *) unescaped_buffer, 1024, &unescaped_len, &used, @@ -114,16 +114,19 @@ handle_response (MMSerialPort *port, g_set_error_literal (&dm_error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Failed to unescape QCDM packet."); - g_byte_array_free (unescaped, TRUE); - unescaped = NULL; + g_free (unescaped_buffer); + unescaped_buffer = NULL; } else if (more) { /* Need more data; we shouldn't have gotten here since the parse * function checks for the end-of-frame marker, but whatever. */ + g_free (unescaped_buffer); return 0; } else { /* Successfully decapsulated the DM command */ - unescaped->len = (guint) unescaped_len; + g_assert (unescaped_len <= 1024); + unescaped_buffer = g_realloc (unescaped_buffer, unescaped_len); + unescaped = g_byte_array_new_take (unescaped_buffer, unescaped_len); } callback: @@ -133,7 +136,7 @@ callback: callback_data); if (unescaped) - g_byte_array_free (unescaped, TRUE); + g_byte_array_unref (unescaped); g_clear_error (&dm_error); return start + used; |