[PATCH] cinterion: check error returned by g_task_propagate_error instead

Dan Williams dcbw at redhat.com
Thu Jul 6 21:42:50 UTC 2017


On Thu, 2017-07-06 at 12:35 -0700, 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/cinterion/mm-broadband-bearer-cinterion.c | 9 +++++++--
>  plugins/cinterion/mm-broadband-modem-cinterion.c  | 6 +++++-
>  plugins/cinterion/mm-common-cinterion.c           | 7 +++++--
>  3 files changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c
> b/plugins/cinterion/mm-broadband-bearer-cinterion.c
> index a1c699e9..438fb599 100644
> --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c
> +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c
> @@ -85,10 +85,15 @@ load_connection_status_finish
> (MMBaseBearer  *bearer,
>                                 GAsyncResult  *res,
>                                 GError       **error)
>  {
> +    GError *inner_error = NULL;
>      gssize aux;
>  
> -    aux = g_task_propagate_int (G_TASK (res), error);
> -    return (aux < 0 ? MM_BEARER_CONNECTION_STATUS_UNKNOWN :
> (MMBearerConnectionStatus) aux);
> +    aux = 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) aux;
>  }
>  
>  static void
> diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c
> b/plugins/cinterion/mm-broadband-modem-cinterion.c
> index c147c2f6..0768fac7 100644
> --- a/plugins/cinterion/mm-broadband-modem-cinterion.c
> +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c
> @@ -582,10 +582,14 @@ load_access_technologies_finish
> (MMIfaceModem             *self,
>                                   guint                    *mask,
>                                   GError                  **error)
>  {
> +    GError *inner_error = NULL;
>      gssize val;
>  
> -    if ((val = g_task_propagate_int (G_TASK (res), error)) < 0)
> +    val = g_task_propagate_int (G_TASK (res), error);

error -> &inner_error I presume?

> +    if (inner_error) {
> +        g_propagate_error (error, inner_error);
>          return FALSE;
> +    }
>  
>      *access_technologies = (MMModemAccessTechnology) val;
>      *mask = MM_MODEM_ACCESS_TECHNOLOGY_ANY;
> diff --git a/plugins/cinterion/mm-common-cinterion.c
> b/plugins/cinterion/mm-common-cinterion.c
> index 3f2b3994..67bc5b3b 100644
> --- a/plugins/cinterion/mm-common-cinterion.c
> +++ b/plugins/cinterion/mm-common-cinterion.c
> @@ -122,11 +122,14 @@
> mm_common_cinterion_location_load_capabilities_finish
> (MMIfaceModemLocation  *se
>                                                         GAsyncResult 
>          *res,
>                                                         GError       
>         **error)
>  {
> +    GError *inner_error = NULL;
>      gssize aux;
>  
> -    if ((aux = g_task_propagate_int (G_TASK (res), error)) < 0)
> +    aux = g_task_propagate_int (G_TASK (res), &inner_error);
> +    if (inner_error) {
> +        g_propagate_error (error, inner_error);
>          return MM_MODEM_LOCATION_SOURCE_NONE;
> -
> +    }
>      return (MMModemLocationSource) aux;
>  }
>  


More information about the ModemManager-devel mailing list