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

Gregory Hainaut gregory.hainaut at gmail.com
Tue Apr 4 16:29:45 UTC 2017


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
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;
-- 
2.1.4



More information about the mesa-dev mailing list