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;
}
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;
}
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;
* A fixed-size blob has a fixed block of data that will not be freed on
* blob_finish and will never be grown. If we hit the end, we simply start
* returning false from the write functions.
+ *
+ * If a fixed-size blob has a NULL data pointer then the data is written but
+ * it otherwise operates normally. This can be used to determine the size
+ * that will be required to write a given data structure.
*/
void
blob_init_fixed(struct blob *blob, void *data, size_t size);