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) {
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);
}
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; \
}