[Mesa-dev] [PATCH] gallium: fix return value check
Jan Vesely
jv356 at scarletmail.rutgers.edu
Wed Sep 7 15:07:21 UTC 2016
On Wed, 2016-09-07 at 17:34 +0300, Martina Kollarova wrote:
> A possible error (-1) was being lost because it was first converted
> to an
> unsigned int and only then checked.
> ---
> src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
> b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
> index 07eca99..b8326fb 100644
> --- a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
> +++ b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
> @@ -252,18 +252,18 @@ kms_sw_displaytarget_add_from_prime(struct
> kms_sw_winsys *kms_sw, int fd,
> if (!kms_sw_dt)
> return NULL;
>
> + int lseek_ret = lseek(fd, 0, SEEK_END);
I don't think it's safe to use int here. From the man page:
lseek(2) uses the type off_t. This is a 32-bit signed type on 32-bit
architectures, unless one compiles with
#define _FILE_OFFSET_BITS 64
in which case it is a 64-bit signed type.
not that I expect the file to be >2GB, but i's better to be safe (mesa uses -D_FILE_OFFSET_BITS=64)
Jan
> + if (lseek_ret == (off_t)-1) {
> + FREE(kms_sw_dt);
> + return NULL;
> + }
> + kms_sw_dt->size = lseek_ret;
> kms_sw_dt->ref_count = 1;
> kms_sw_dt->handle = handle;
> - kms_sw_dt->size = lseek(fd, 0, SEEK_END);
> kms_sw_dt->width = width;
> kms_sw_dt->height = height;
> kms_sw_dt->stride = stride;
>
> - if (kms_sw_dt->size == (off_t)-1) {
> - FREE(kms_sw_dt);
> - return NULL;
> - }
> -
> lseek(fd, 0, SEEK_SET);
>
> list_add(&kms_sw_dt->link, &kms_sw->bo_list);
--
Jan Vesely <jv356 at scarletmail.rutgers.edu>
More information about the mesa-dev
mailing list