Mesa (main): util/blob: use memcpy in read functions

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jul 7 12:52:37 UTC 2022


Module: Mesa
Branch: main
Commit: 3c61f2cc15dddc212fbc17f561fe496029ed5661
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3c61f2cc15dddc212fbc17f561fe496029ed5661

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Mon May 23 10:33:25 2022 +0200

util/blob: use memcpy in read functions

Type casting may require specific alignment on some platforms;
since the input data can be provided by the application we can't
require any alignment.

Switch to using memcpy like the write functions do, and drop the
asserts.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6493
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16662>

---

 src/util/blob.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/src/util/blob.c b/src/util/blob.c
index 67f6bb2567c..b293df9c5df 100644
--- a/src/util/blob.c
+++ b/src/util/blob.c
@@ -85,7 +85,6 @@ grow_to_fit(struct blob *blob, size_t additional)
 bool
 blob_align(struct blob *blob, size_t alignment)
 {
-   assert(align64((uintptr_t)blob->data, alignment) == (uintptr_t)blob->data);
    const size_t new_size = align64(blob->size, alignment);
 
    if (blob->size < new_size) {
@@ -103,7 +102,6 @@ blob_align(struct blob *blob, size_t alignment)
 void
 blob_reader_align(struct blob_reader *blob, size_t alignment)
 {
-   assert(align64((uintptr_t)blob->data, alignment) == (uintptr_t)blob->data);
    blob->current = blob->data + align64(blob->current - blob->data, alignment);
 }
 
@@ -310,22 +308,14 @@ blob_skip_bytes(struct blob_reader *blob, size_t size)
       blob->current += size;
 }
 
-/* These next three read functions have identical form. If we add any beyond
- * these first three we should probably switch to generating these with a
- * preprocessor macro.
-*/
-
 #define BLOB_READ_TYPE(name, type)         \
 type                                       \
 name(struct blob_reader *blob)             \
 {                                          \
-   type ret;                               \
+   type ret = 0;                           \
    int size = sizeof(ret);                 \
    blob_reader_align(blob, size);          \
-   if (! ensure_can_read(blob, size))      \
-      return 0;                            \
-   ret = *((type*) blob->current);         \
-   blob->current += size;                  \
+   blob_copy_bytes(blob, &ret, size);      \
    return ret;                             \
 }
 



More information about the mesa-commit mailing list