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@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16662>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2022-05-23 10:33:25 +02:00 committed by Marge Bot
parent 8856379a03
commit 3c61f2cc15
1 changed files with 2 additions and 12 deletions

View File

@ -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; \
}