[PATCH] novatel-lte: check error returned by g_task_propagate_error instead

Aleksander Morgado aleksander at aleksander.es
Fri Jul 7 08:16:34 UTC 2017


On 06/07/17 21:34, 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.
> ---
>  plugins/novatel/mm-broadband-bearer-novatel-lte.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 

Pushed to git master, thanks!

> diff --git a/plugins/novatel/mm-broadband-bearer-novatel-lte.c b/plugins/novatel/mm-broadband-bearer-novatel-lte.c
> index e06a6bec..51e3f645 100644
> --- a/plugins/novatel/mm-broadband-bearer-novatel-lte.c
> +++ b/plugins/novatel/mm-broadband-bearer-novatel-lte.c
> @@ -87,10 +87,15 @@ load_connection_status_finish (MMBaseBearer  *bearer,
>                                 GAsyncResult  *res,
>                                 GError       **error)
>  {
> +    GError *inner_error = NULL;
>      gssize value;
>  
> -    value = g_task_propagate_int (G_TASK (res), error);
> -    return (value < 0 ? MM_BEARER_CONNECTION_STATUS_UNKNOWN : (MMBearerConnectionStatus) value);
> +    value = g_task_propagate_int (G_TASK (res), &inner_error);
> +    if (inner_error) {
> +        g_propagate_error (error, inner_error);
> +        return MM_BEARER_CONNECTION_STATUS_UNKNOWN;
> +    }
> +    return (MMBearerConnectionStatus)value;
>  }
>  
>  static void
> 


-- 
Aleksander
https://aleksander.es


More information about the ModemManager-devel mailing list