[Mesa-dev] [PATCH 2/2] mesa: add typesize validation to resource functions

Tapani Pälli tapani.palli at intel.com
Fri Aug 11 07:45:15 UTC 2017


This makes development/changes to program resource code more safe.
Patch also makes helper functions static.

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
 src/mesa/main/shader_query.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index f2bdcaa..d1fc5e9 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -49,8 +49,9 @@ program_resource_location(struct gl_program_resource *res,
  * Warning! this is not type safe so be *very* careful when using these.
  */
 #define DECL_RESOURCE_FUNC(name, type) \
-const type * RESOURCE_ ## name (gl_program_resource *res) { \
+static const type * RESOURCE_ ## name (gl_program_resource *res) { \
    assert(res->Data); \
+   assert(res->TypeSize == sizeof(type));\
    return (type *) res->Data; \
 }
 
-- 
2.9.4



More information about the mesa-dev mailing list