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.
This commit is contained in:
@@ -59,7 +59,7 @@ AC_SUBST(GETTEXT_PACKAGE)
|
|||||||
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
|
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
|
||||||
|
|
||||||
PKG_CHECK_MODULES(MM,
|
PKG_CHECK_MODULES(MM,
|
||||||
glib-2.0 >= 2.30.2
|
glib-2.0 >= 2.32
|
||||||
gmodule-2.0
|
gmodule-2.0
|
||||||
gobject-2.0
|
gobject-2.0
|
||||||
gio-2.0
|
gio-2.0
|
||||||
@@ -68,7 +68,7 @@ AC_SUBST(MM_CFLAGS)
|
|||||||
AC_SUBST(MM_LIBS)
|
AC_SUBST(MM_LIBS)
|
||||||
|
|
||||||
PKG_CHECK_MODULES(LIBMM_GLIB,
|
PKG_CHECK_MODULES(LIBMM_GLIB,
|
||||||
glib-2.0 >= 2.30.2
|
glib-2.0 >= 2.32
|
||||||
gobject-2.0
|
gobject-2.0
|
||||||
gio-2.0
|
gio-2.0
|
||||||
gio-unix-2.0)
|
gio-unix-2.0)
|
||||||
@@ -76,7 +76,7 @@ AC_SUBST(LIBMM_GLIB_CFLAGS)
|
|||||||
AC_SUBST(LIBMM_GLIB_LIBS)
|
AC_SUBST(LIBMM_GLIB_LIBS)
|
||||||
|
|
||||||
PKG_CHECK_MODULES(MMCLI,
|
PKG_CHECK_MODULES(MMCLI,
|
||||||
glib-2.0 >= 2.30.2
|
glib-2.0 >= 2.32
|
||||||
gobject-2.0
|
gobject-2.0
|
||||||
gio-2.0)
|
gio-2.0)
|
||||||
AC_SUBST(MMCLI_CFLAGS)
|
AC_SUBST(MMCLI_CFLAGS)
|
||||||
|
@@ -81,6 +81,7 @@ handle_response (MMSerialPort *port,
|
|||||||
{
|
{
|
||||||
MMQcdmSerialResponseFn response_callback = (MMQcdmSerialResponseFn) callback;
|
MMQcdmSerialResponseFn response_callback = (MMQcdmSerialResponseFn) callback;
|
||||||
GByteArray *unescaped = NULL;
|
GByteArray *unescaped = NULL;
|
||||||
|
guint8 *unescaped_buffer;
|
||||||
GError *dm_error = NULL;
|
GError *dm_error = NULL;
|
||||||
gsize used = 0;
|
gsize used = 0;
|
||||||
gsize start = 0;
|
gsize start = 0;
|
||||||
@@ -101,11 +102,10 @@ handle_response (MMSerialPort *port,
|
|||||||
goto callback;
|
goto callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: don't munge around with byte array internals */
|
unescaped_buffer = g_malloc (1024);
|
||||||
unescaped = g_byte_array_sized_new (1024);
|
|
||||||
success = dm_decapsulate_buffer ((const char *) (response->data + start),
|
success = dm_decapsulate_buffer ((const char *) (response->data + start),
|
||||||
response->len - start,
|
response->len - start,
|
||||||
(char *) unescaped->data,
|
(char *) unescaped_buffer,
|
||||||
1024,
|
1024,
|
||||||
&unescaped_len,
|
&unescaped_len,
|
||||||
&used,
|
&used,
|
||||||
@@ -114,16 +114,19 @@ handle_response (MMSerialPort *port,
|
|||||||
g_set_error_literal (&dm_error,
|
g_set_error_literal (&dm_error,
|
||||||
MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||||
"Failed to unescape QCDM packet.");
|
"Failed to unescape QCDM packet.");
|
||||||
g_byte_array_free (unescaped, TRUE);
|
g_free (unescaped_buffer);
|
||||||
unescaped = NULL;
|
unescaped_buffer = NULL;
|
||||||
} else if (more) {
|
} else if (more) {
|
||||||
/* Need more data; we shouldn't have gotten here since the parse
|
/* Need more data; we shouldn't have gotten here since the parse
|
||||||
* function checks for the end-of-frame marker, but whatever.
|
* function checks for the end-of-frame marker, but whatever.
|
||||||
*/
|
*/
|
||||||
|
g_free (unescaped_buffer);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
/* Successfully decapsulated the DM command */
|
/* 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:
|
callback:
|
||||||
@@ -133,7 +136,7 @@ callback:
|
|||||||
callback_data);
|
callback_data);
|
||||||
|
|
||||||
if (unescaped)
|
if (unescaped)
|
||||||
g_byte_array_free (unescaped, TRUE);
|
g_byte_array_unref (unescaped);
|
||||||
g_clear_error (&dm_error);
|
g_clear_error (&dm_error);
|
||||||
|
|
||||||
return start + used;
|
return start + used;
|
||||||
|
Reference in New Issue
Block a user