Skip to contentSkip to conversation

xf86drm: Fix operator precedence

PATCH In review Thierry Reding 2 participants 2 messages Feb 20, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xf86drm: Fix operator precedence

From: Thierry Reding <[email protected]>

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.

---
 xf86drm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xf86drm.c +2 -2
index d006bb38f800..5de37083c9a3 100644
@@ -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;
Signature · 6 lines
2.20.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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.

---
 xf86drm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xf86drm.c +1 -1
index d006bb38f800..5de37083c9a3 100644
@@ -3606,14 +3606,14 @@ static int drmParseOFDeviceInfo(int maj, int min, char ***compatible)
             free(value);
         }
 
-        *compatible[i] = tmp_name;
+        (*compatible)[i] = tmp_name;
     }

xf86drm.c static int drmParseOFDeviceInfo(int maj, int min, char ***compatible) · line 3619

Quoted 10 lines
xf86drm.c +1 -1
 
     return 0;
 
 free:
     while (i--)
-        free(*compatible[i]);
+        free((*compatible)[i]);
 
     free(*compatible);
     return err;

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel