summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/blob.c
diff options
context:
space:
mode:
authorNicolai Hähnle <[email protected]>2017-06-24 10:26:29 +0200
committerNicolai Hähnle <[email protected]>2017-07-05 12:26:10 +0200
commit3628efedf29d2b5e181ea88f24db518038ab1a92 (patch)
treeeb49d9cc4edf8b5aff0212bb73184f1d1f3cd50b /src/compiler/glsl/blob.c
parent210ebd4b9c1b510ff1b29a81aa7512ea77056966 (diff)
glsl/blob: add valgrind checks that written data is defined
Undefined data will eventually trigger a valgrind error while computing its CRC32 while writing it into the disk cache, but at that point, it is basically impossible to track down where the undefined data came from. With this change, finding the origin of undefined data becomes easy. v2: remove duplicate VALGRIND_CFLAGS (Emil) Reviewed-by: Timothy Arceri <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src/compiler/glsl/blob.c')
-rw-r--r--src/compiler/glsl/blob.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/compiler/glsl/blob.c b/src/compiler/glsl/blob.c
index db362520650..3c4aed8524d 100644
--- a/src/compiler/glsl/blob.c
+++ b/src/compiler/glsl/blob.c
@@ -26,6 +26,14 @@
#include "main/macros.h"
#include "blob.h"
+#ifdef HAVE_VALGRIND
+#include <valgrind.h>
+#include <memcheck.h>
+#define VG(x) x
+#else
+#define VG(x)
+#endif
+
#define BLOB_INITIAL_SIZE 4096
/* Ensure that \blob will be able to fit an additional object of size
@@ -110,6 +118,8 @@ blob_overwrite_bytes(struct blob *blob,
if (blob->size < offset + to_write)
return false;
+ VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
+
memcpy(blob->data + offset, bytes, to_write);
return true;
@@ -121,6 +131,8 @@ blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write)
if (! grow_to_fit(blob, to_write))
return false;
+ VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
+
memcpy(blob->data + blob->size, bytes, to_write);
blob->size += to_write;