From a8c015f72b358b5f31f35408da8d0983c864aa25 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 14 Aug 2021 20:53:15 +0200 Subject: [PATCH] mp4: Drop integer return type from modify_moov(). This function returns either zero or one to indicate success. On success, a pointer to a buffer and the buffer size are returned. It is simpler and less redundant to indicate failure by returning a NULL buffer pointer. Rather than using a void ** argument for the buffer, let the function return void *. --- mp4.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mp4.c b/mp4.c index bec03710..7f223bc3 100644 --- a/mp4.c +++ b/mp4.c @@ -1373,8 +1373,7 @@ static uint32_t fix_byte_order_32(uint32_t src) return read_u32_be(&src); } -static uint32_t modify_moov(struct mp4 *f, void **out_buffer, - uint32_t *out_size) +static void *modify_moov(struct mp4 *f, uint32_t *out_size) { uint64_t total_base = f->moov_offset + 8; uint32_t total_size = (uint32_t) (f->moov_size - 8); @@ -1383,7 +1382,7 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, uint32_t udta_size, meta_size, ilst_size; uint32_t new_ilst_size; - void *new_ilst_buffer; + void *new_ilst_buffer, *out_buffer; uint8_t *p_out; int32_t size_delta; @@ -1393,7 +1392,7 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, void *new_udta_buffer; uint32_t new_udta_size; if (!create_udta(&f->meta, &new_udta_buffer, &new_udta_size)) - return 0; + return NULL; buf = membuffer_create(); set_position(f, total_base); @@ -1405,9 +1404,9 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, free(new_udta_buffer); *out_size = membuffer_get_size(buf); - *out_buffer = membuffer_detach(buf); + out_buffer = membuffer_detach(buf); membuffer_free(buf); - return 1; + return out_buffer; } udta_offset = get_position(f); udta_size = read_int32(f); @@ -1417,7 +1416,7 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, uint32_t new_meta_size; if (!create_meta(&f->meta, &new_meta_buffer, &new_meta_size)) - return 0; + return NULL; buf = membuffer_create(); set_position(f, total_base); @@ -1433,22 +1432,23 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, free(new_meta_buffer); *out_size = membuffer_get_size(buf); - *out_buffer = membuffer_detach(buf); + out_buffer = membuffer_detach(buf); membuffer_free(buf); - return 1; + return out_buffer; } meta_offset = get_position(f); meta_size = read_int32(f); + /* shouldn't happen, find_atom_v2 above takes care of it */ if (!find_atom(f, meta_offset + 12, meta_size - 12, "ilst")) - return 0; /* shouldn't happen, find_atom_v2 above takes care of it */ + return NULL; ilst_offset = get_position(f); ilst_size = read_int32(f); if (!create_ilst(&f->meta, &new_ilst_buffer, &new_ilst_size)) - return 0; + return NULL; size_delta = new_ilst_size - (ilst_size - 8); *out_size = total_size + size_delta; - *out_buffer = para_malloc(*out_size); - p_out = (uint8_t *)*out_buffer; + out_buffer = para_malloc(*out_size); + p_out = out_buffer; set_position(f, total_base); read_data(f, p_out, (uint32_t) (udta_offset - total_base)); p_out += (uint32_t) (udta_offset - total_base); @@ -1474,7 +1474,7 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, read_data(f, p_out, (uint32_t) (total_size - (ilst_offset - total_base) - ilst_size)); free(new_ilst_buffer); - return 1; + return out_buffer; } static int32_t write_data(struct mp4 *f, void *data, uint32_t size) @@ -1501,7 +1501,8 @@ int32_t mp4_meta_update(struct mp4 *f) uint32_t new_moov_size; set_position(f, 0); - if (!modify_moov(f, &new_moov_data, &new_moov_size)) { + new_moov_data = modify_moov(f, &new_moov_size); + if (!new_moov_data ) { mp4_close(f); return 0; } -- 2.39.2