return buf->data;
}
-static void membuffer_set_error(struct membuffer *buf)
-{
- buf->error = 1;
-}
-
-static unsigned membuffer_transfer_from_file(struct membuffer *buf, struct mp4 *src,
+static bool membuffer_transfer_from_file(struct membuffer *buf, struct mp4 *src,
unsigned bytes)
{
unsigned oldsize;
oldsize = membuffer_get_size(buf);
if (membuffer_write(buf, 0, bytes) != bytes)
- return 0;
+ return false;
bufptr = membuffer_get_ptr(buf);
if (bufptr == 0)
- return 0;
+ return false;
if ((unsigned)read_data(src, (char *) bufptr + oldsize, bytes) !=
bytes) {
- membuffer_set_error(buf);
- return 0;
+ membuffer_free(buf);
+ return false;
}
-
- return bytes;
+ return true;
}
static uint32_t create_meta(const struct mp4_metadata *meta, void **out_buffer,
buf = membuffer_create();
set_position(f, total_base);
- membuffer_transfer_from_file(buf, f, total_size);
-
+ if (!membuffer_transfer_from_file(buf, f, total_size)) {
+ free(new_udta_buffer);
+ return NULL;
+ }
membuffer_write_atom(buf, "udta", new_udta_size,
new_udta_buffer);
buf = membuffer_create();
set_position(f, total_base);
- membuffer_transfer_from_file(buf, f,
- (uint32_t)(udta_offset - total_base));
+ if (!membuffer_transfer_from_file(buf, f,
+ udta_offset - total_base)) {
+ free(new_meta_buffer);
+ return NULL;
+ }
membuffer_write_int32(buf, udta_size + 8 + new_meta_size);
membuffer_write_atom_name(buf, "udta");
- membuffer_transfer_from_file(buf, f, udta_size);
+ if (!membuffer_transfer_from_file(buf, f, udta_size)) {
+ free(new_meta_buffer);
+ return NULL;
+ }
membuffer_write_atom(buf, "meta", new_meta_size,
new_meta_buffer);