Re: [Mesa-dev] [PATCH V2 7/8] glsl: create type name for arrays of arrays

2014-01-21 Thread Paul Berry
On 21 January 2014 04:19, Timothy Arceri  wrote:

> We need to insert outermost dimensions in the correct spot otherwise
> the dimension order will be backwards
>
> Signed-off-by: Timothy Arceri 
> ---
>  src/glsl/glsl_types.cpp | 14 --
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
> index 12d4ac0..f7f3117 100644
> --- a/src/glsl/glsl_types.cpp
> +++ b/src/glsl/glsl_types.cpp
> @@ -300,8 +300,18 @@ glsl_type::glsl_type(const glsl_type *array, unsigned
> length) :
>
> if (length == 0)
>snprintf(n, name_length, "%s[]", array->name);
> -   else
> -  snprintf(n, name_length, "%s[%u]", array->name, length);
> +   else {
> +  /* insert outermost dimensions in the correct spot */
> +  const char *pos = strchr(array->name, '[');
> +  if (pos) {
> + int idx = pos - array->name;
> + snprintf(n, idx+1, "%s", array->name);
> + snprintf(n + idx, name_length, "[%u]", length);
> + snprintf(n + strlen(n), name_length, "%s", array->name + idx);
>

Technically the last two snprintf's are unsafe, since the second argument
is a length, so we need to subtract the offset we supplied to the first
argument.

Also, there's no need to split the second snprintf from the third; both of
them can be combined to:

snprintf(n + idx, name_length - idx, "[%u]%s", length, array->name + idx);

Good catch on noticing that it's necessary to reverse the order of the
dimensions.  With that fixed, this patch is:

Reviewed-by: Paul Berry 


> +  } else {
> + snprintf(n, name_length, "%s[%u]", array->name, length);
> +  }
> +   }
>
> this->name = n;
>  }
> --
> 1.8.3.1
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH V2 7/8] glsl: create type name for arrays of arrays

2014-01-21 Thread Timothy Arceri
We need to insert outermost dimensions in the correct spot otherwise
the dimension order will be backwards

Signed-off-by: Timothy Arceri 
---
 src/glsl/glsl_types.cpp | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 12d4ac0..f7f3117 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -300,8 +300,18 @@ glsl_type::glsl_type(const glsl_type *array, unsigned 
length) :
 
if (length == 0)
   snprintf(n, name_length, "%s[]", array->name);
-   else
-  snprintf(n, name_length, "%s[%u]", array->name, length);
+   else {
+  /* insert outermost dimensions in the correct spot */
+  const char *pos = strchr(array->name, '[');
+  if (pos) {
+ int idx = pos - array->name;
+ snprintf(n, idx+1, "%s", array->name);
+ snprintf(n + idx, name_length, "[%u]", length);
+ snprintf(n + strlen(n), name_length, "%s", array->name + idx);
+  } else {
+ snprintf(n, name_length, "%s[%u]", array->name, length);
+  }
+   }
 
this->name = n;
 }
-- 
1.8.3.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev