[PATCH] iface-modem: check error returned by g_task_propagate_error instead
Aleksander Morgado
aleksander at aleksander.es
Thu Jul 6 08:51:29 UTC 2017
On 06/07/17 07:20, Ben Chan wrote:
> When returning an enum value via g_task_return_int, some code assumes
> the enum value is always non-negative and thus considers that a negative
> value implies an error. This assumption could be invalidated if a
> negative value is later added to the enum. To make it less error prone
> to future changes, this patch modifies the code to check if the GError
> argument to g_task_propagate_error is populated instead.
> ---
> src/mm-iface-modem.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
Pushed to git master, thanks.
> diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c
> index cd462a38..e79e55c3 100644
> --- a/src/mm-iface-modem.c
> +++ b/src/mm-iface-modem.c
> @@ -245,11 +245,15 @@ internal_load_unlock_required_finish (MMIfaceModem *self,
> GAsyncResult *res,
> GError **error)
> {
> + GError *inner_error = NULL;
> gssize value;
>
> - value = g_task_propagate_int (G_TASK (res), error);
> -
> - return value < 0 ? MM_MODEM_LOCK_UNKNOWN : (MMModemLock)value;
> + value = g_task_propagate_int (G_TASK (res), &inner_error);
> + if (inner_error) {
> + g_propagate_error (error, inner_error);
> + return MM_MODEM_LOCK_UNKNOWN;
> + }
> + return (MMModemLock)value;
> }
>
> static void internal_load_unlock_required_context_step (GTask *task);
> @@ -2990,10 +2994,15 @@ mm_iface_modem_update_lock_info_finish (MMIfaceModem *self,
> GAsyncResult *res,
> GError **error)
> {
> + GError *inner_error = NULL;
> gssize value;
>
> - value = g_task_propagate_int (G_TASK (res), error);
> - return value < 0 ? MM_MODEM_LOCK_UNKNOWN : (MMModemLock)value;
> + value = g_task_propagate_int (G_TASK (res), &inner_error);
> + if (inner_error) {
> + g_propagate_error (error, inner_error);
> + return MM_MODEM_LOCK_UNKNOWN;
> + }
> + return (MMModemLock)value;
> }
>
> static void update_lock_info_context_step (GTask *task);
>
--
Aleksander
https://aleksander.es
More information about the ModemManager-devel
mailing list