diff mbox series

[libdrm] xf86drm: Fix operator precedence

Message ID 20190220111725.14673-1-thierry.reding@gmail.com (mailing list archive)
State New, archived
Headers show
Series [libdrm] xf86drm: Fix operator precedence | expand

Commit Message

Thierry Reding Feb. 20, 2019, 11:17 a.m. UTC
From: Thierry Reding <treding@nvidia.com>

The array subscription operator ([]) has higher precedence than the
indirection operator (*), so we need to use parentheses to properly
instruct the compiler to dereference the pointer to an array first,
and then subscript into the array.

Fixes a crash observed on Tegra.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 xf86drm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Frank Binns Feb. 20, 2019, 11:59 a.m. UTC | #1
Reviewed-by: Frank Binns <frank.binns@imgtec.com>

Thierry Reding <thierry.reding@gmail.com> writes:

> From: Thierry Reding <treding@nvidia.com>
>
> The array subscription operator ([]) has higher precedence than the
> indirection operator (*), so we need to use parentheses to properly
> instruct the compiler to dereference the pointer to an array first,
> and then subscript into the array.
>
> Fixes a crash observed on Tegra.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  xf86drm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index d006bb38f800..5de37083c9a3 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -3606,14 +3606,14 @@ static int drmParseOFDeviceInfo(int maj, int min, char ***compatible)
>              free(value);
>          }
>  
> -        *compatible[i] = tmp_name;
> +        (*compatible)[i] = tmp_name;
>      }
>  
>      return 0;
>  
>  free:
>      while (i--)
> -        free(*compatible[i]);
> +        free((*compatible)[i]);
>  
>      free(*compatible);
>      return err;
diff mbox series

Patch

diff --git a/xf86drm.c b/xf86drm.c
index d006bb38f800..5de37083c9a3 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3606,14 +3606,14 @@  static int drmParseOFDeviceInfo(int maj, int min, char ***compatible)
             free(value);
         }
 
-        *compatible[i] = tmp_name;
+        (*compatible)[i] = tmp_name;
     }
 
     return 0;
 
 free:
     while (i--)
-        free(*compatible[i]);
+        free((*compatible)[i]);
 
     free(*compatible);
     return err;