[Mesa-dev] [PATCH v2] glsl/blob: handle NULL ptr in blob_write_string/blob_read_string

Timothy Arceri tarceri at itsqueeze.com
Tue Apr 4 23:09:45 UTC 2017


On 05/04/17 02:29, Gregory Hainaut wrote:
> Context:
> Nouveau uses NULL strings for unnamed parameter of texture gather
> offsets opcode.
>
> Fix piglit crashes of the 'texturegatheroffsets' tests on Nouveau
>
> v2: based on Nicolai feedback

Hi Gregory,

Nicolai suggested you change the caller of create a new helper function 
for the case where string can be NULL. e.g blob_write_optional_string()

The change below causes an extra read/write which is not required for 
ever other use of this function. Please create the additional function 
as a wrapper around blob_write_string()

Thanks,
Tim

> Adds an extra flag byte that will be null if the string is null.
> This way, null strings are handled transparently for Mesa.
>
> Signed-off-by: Gregory Hainaut <gregory.hainaut at gmail.com>
> ---
>  src/compiler/glsl/blob.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/src/compiler/glsl/blob.c b/src/compiler/glsl/blob.c
> index 769ebf1..b520044 100644
> --- a/src/compiler/glsl/blob.c
> +++ b/src/compiler/glsl/blob.c
> @@ -176,7 +176,18 @@ blob_write_intptr(struct blob *blob, intptr_t value)
>  bool
>  blob_write_string(struct blob *blob, const char *str)
>  {
> -   return blob_write_bytes(blob, str, strlen(str) + 1);
> +   bool ret = true;
> +   const uint8_t flag = str != NULL ? 1 : 0;
> +
> +   ret = blob_write_bytes(blob, &flag, 1);
> +
> +   if (!ret)
> +      return false;
> +
> +   if (flag)
> +      ret = blob_write_bytes(blob, str, strlen(str) + 1);
> +
> +   return ret;
>  }
>
>  void
> @@ -293,8 +304,15 @@ blob_read_string(struct blob_reader *blob)
>  {
>     int size;
>     char *ret;
> +   uint8_t *flag;
>     uint8_t *nul;
>
> +   flag = (uint8_t *)blob_read_bytes(blob, 1);
> +
> +   if (flag == NULL || *flag == 0) {
> +      return NULL;
> +   }
> +
>     /* If we're already at the end, then this is an overrun. */
>     if (blob->current >= blob->end) {
>        blob->overrun = true;
>


More information about the mesa-dev mailing list