[Spice-devel] [PATCH spice-gtk 1/6] channel: return "unknown" in spice_channel_type_to_string()

Frediano Ziglio fziglio at redhat.com
Fri Aug 11 00:11:32 UTC 2017


> 
> From: Marc-André Lureau <marcandre.lureau at redhat.com>
> 
> This fixes the following gcc warning:
> 
> spice-channel.c: In function ‘spice_channel_constructed’:
> spice-channel.c:144:41: error: ‘%s’ directive output may be truncated writing
> likely 20 or more bytes into a region of size 16
> [-Werror=format-truncation=]
>      snprintf(c->name, sizeof(c->name), "%s-%d:%d",
>                                          ^~
> spice-channel.c:144:40: note: assuming directive output of 20 bytes
>      snprintf(c->name, sizeof(c->name), "%s-%d:%d",
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
> ---
>  src/spice-channel.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/spice-channel.c b/src/spice-channel.c
> index 4c3db9d..7cd6251 100644
> --- a/src/spice-channel.c
> +++ b/src/spice-channel.c
> @@ -2130,13 +2130,13 @@ static const char *to_string[] = {
>   **/
>  const gchar* spice_channel_type_to_string(gint type)
>  {
> -    const char *str = NULL;
> +    const char *str = "unknown";
>  
>      if (type >= 0 && type < G_N_ELEMENTS(to_string)) {
>          str = to_string[type];
>      }
>  
> -    return str ? str : "unknown channel type";
> +    return str;
>  }
>  
>  /**

Note that some array entries contains NULL so changing the code
that way you are returning NULL in some cases while before
was never NULL. Simply modifying the string solve the gcc issue
without this regression. Snir was working in the same issue but
you arrived first with a patch.
Potentially this change the reply to a public API. Maybe to avoid
potentially having an "unknown" channel we could use "UNKNOWN"
or "Unknown" ?

Frediano


More information about the Spice-devel mailing list