From: Andre Noll Date: Thu, 26 Aug 2021 20:11:40 +0000 (+0200) Subject: mp4: Check the return value of ->truncate(). X-Git-Tag: v0.7.1~7^2~16 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=6b27f3436334bc89cad31b6fff5399b0d17c3f38;p=paraslash.git mp4: Check the return value of ->truncate(). This callback is implemented as a simple wrapper for the ftruncate() system call, which can fail for a number of reasons. Currently the callback returns unsigned and the return value is ignored. Fortunately, this is easy to fix. --- diff --git a/aac_afh.c b/aac_afh.c index ae1e99dc..b45db477 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -190,7 +190,7 @@ static ssize_t aac_afh_meta_write_cb(void *user_data, void *dest, size_t count) return write(fd, dest, count); } -static uint32_t aac_afh_meta_truncate_cb(void *user_data) +static int aac_afh_meta_truncate_cb(void *user_data) { int fd = *(int *)user_data; off_t offset = lseek(fd, 0, SEEK_CUR); diff --git a/mp4.c b/mp4.c index 9ed0fcbb..0bddac9c 100644 --- a/mp4.c +++ b/mp4.c @@ -882,8 +882,9 @@ int mp4_meta_update(struct mp4 *f) ret = write_data(f, new_moov_data, new_moov_size); if (ret < 0) goto free_moov; - f->cb->truncate(f->cb->user_data); - ret = 1; + ret = f->cb->truncate(f->cb->user_data); + if (ret < 0) + ret = -ERRNO_TO_PARA_ERROR(errno); free_moov: free(new_moov_data); return ret; diff --git a/mp4.h b/mp4.h index 0775956b..49c4be18 100644 --- a/mp4.h +++ b/mp4.h @@ -2,7 +2,7 @@ struct mp4_callback { ssize_t (*read)(void *user_data, void *buffer, size_t length); ssize_t (*write)(void *user_data, void *buffer, size_t count); off_t (*seek)(void *user_data, off_t offset, int whence); - uint32_t (*truncate)(void *user_data); + int (*truncate)(void *user_data); void *user_data; };