[PATCH 2/4] xwayland: Remove a useless out-of-memory check

Marek Chalupa mchqwerty at gmail.com
Thu May 14 00:10:59 PDT 2015


Checking for negative return value of snprintf is wrong, but snprintf can
actually "fail". It can truncate the output. However, since sizeof name is
256 and the length of "XWAYLAND%d" is always shorter that this, it is safe
here.

Reviewed-by: Marek Chalupa <mchqwerty at gmail.com>

On Tue, May 12, 2015 at 7:21 PM, Dima Ryazanov <dima at gmail.com> wrote:

> snprintf does not allocate memory, so we can never get an out-of-memory
> error.
>
> (Also, the error handler would free xwl_output after it was already
> registered
> as an event listener.)
>
> Signed-off-by: Dima Ryazanov <dima at gmail.com>
> ---
>  hw/xwayland/xwayland-output.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
> index 1d75d0b..4949363 100644
> --- a/hw/xwayland/xwayland-output.c
> +++ b/hw/xwayland/xwayland-output.c
> @@ -167,11 +167,7 @@ xwl_output_create(struct xwl_screen *xwl_screen,
> uint32_t id)
>                                            &wl_output_interface, 2);
>      wl_output_add_listener(xwl_output->output, &output_listener,
> xwl_output);
>
> -    if (snprintf(name, sizeof name, "XWAYLAND%d", serial++) < 0) {
> -        ErrorF("create_output ENOMEM\n");
> -        free(xwl_output);
> -        return NULL;
> -    }
> +    snprintf(name, sizeof name, "XWAYLAND%d", serial++);
>
>      xwl_output->xwl_screen = xwl_screen;
>      xwl_output->randr_crtc = RRCrtcCreate(xwl_screen->screen, xwl_output);
> --
> 2.4.0
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150514/1bb9da72/attachment.html>


More information about the wayland-devel mailing list