[Mesa-dev] [PATCH] glsl: Fix (and validate) comment above glsl_type::name.
Ian Romanick
idr at freedesktop.org
Wed Apr 10 07:40:10 PDT 2013
On 04/09/2013 09:01 PM, Paul Berry wrote:
> The comment above glsl_type::name claimed that it could sometimes be
> NULL. This was wrong--it is never NULL. Many error handling paths
> would segfault if it were.
>
> Fix the comment and add assertions to validate that it really is never
> NULL.
Right... this used to be the case, I think, for compiler-generated
temporaries. We stopped doing that, literally, years ago.
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
> src/glsl/glsl_types.cpp | 4 ++++
> src/glsl/glsl_types.h | 3 +--
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
> index 419761a..df9c5d3 100644
> --- a/src/glsl/glsl_types.cpp
> +++ b/src/glsl/glsl_types.cpp
> @@ -57,6 +57,7 @@ glsl_type::glsl_type(GLenum gl_type,
> length(0)
> {
> init_ralloc_type_ctx();
> + assert(name != NULL);
> this->name = ralloc_strdup(this->mem_ctx, name);
> /* Neither dimension is zero or both dimensions are zero.
> */
> @@ -75,6 +76,7 @@ glsl_type::glsl_type(GLenum gl_type,
> length(0)
> {
> init_ralloc_type_ctx();
> + assert(name != NULL);
> this->name = ralloc_strdup(this->mem_ctx, name);
> memset(& fields, 0, sizeof(fields));
> }
> @@ -91,6 +93,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
> unsigned int i;
>
> init_ralloc_type_ctx();
> + assert(name != NULL);
> this->name = ralloc_strdup(this->mem_ctx, name);
> this->fields.structure = ralloc_array(this->mem_ctx,
> glsl_struct_field, length);
> @@ -114,6 +117,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
> unsigned int i;
>
> init_ralloc_type_ctx();
> + assert(name != NULL);
> this->name = ralloc_strdup(this->mem_ctx, name);
> this->fields.structure = ralloc_array(this->mem_ctx,
> glsl_struct_field, length);
> diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
> index 2f3b19f..31e3dd2 100644
> --- a/src/glsl/glsl_types.h
> +++ b/src/glsl/glsl_types.h
> @@ -132,8 +132,7 @@ struct glsl_type {
> /**
> * Name of the data type
> *
> - * This may be \c NULL for anonymous structures, for arrays, or for
> - * function types.
> + * Will never be \c NULL.
> */
> const char *name;
>
>
More information about the mesa-dev
mailing list