summaryrefslogtreecommitdiffstats
path: root/src/compiler/blob.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-10-12 21:02:48 -0700
committerJason Ekstrand <[email protected]>2017-10-12 21:47:06 -0700
commit8ae03af4ed1ca47a106e5fd7b2d11ce4003aad54 (patch)
treee8c7ecf1fb5fd8a1d24b7cc9558b6bf7188b3b23 /src/compiler/blob.c
parent26f6d4e5c7f38ab1f55d4cdef7013cc3c730f298 (diff)
compiler/blob: Allow for fixed-size blobs with a NULL data pointer
These can be used to easily count up the number of bytes that will be required by "writing" it into the NULL blob. Reviewed-by: Nicolai Hähnle <[email protected]> Reviewed-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/compiler/blob.c')
-rw-r--r--src/compiler/blob.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/compiler/blob.c b/src/compiler/blob.c
index a78fcd41a76..f3ff5d6862e 100644
--- a/src/compiler/blob.c
+++ b/src/compiler/blob.c
@@ -91,7 +91,8 @@ align_blob(struct blob *blob, size_t alignment)
if (!grow_to_fit(blob, new_size - blob->size))
return false;
- memset(blob->data + blob->size, 0, new_size - blob->size);
+ if (blob->data)
+ memset(blob->data + blob->size, 0, new_size - blob->size);
blob->size = new_size;
}
@@ -136,7 +137,8 @@ blob_overwrite_bytes(struct blob *blob,
VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
- memcpy(blob->data + offset, bytes, to_write);
+ if (blob->data)
+ memcpy(blob->data + offset, bytes, to_write);
return true;
}
@@ -149,7 +151,8 @@ blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write)
VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
- memcpy(blob->data + blob->size, bytes, to_write);
+ if (blob->data)
+ memcpy(blob->data + blob->size, bytes, to_write);
blob->size += to_write;
return true;