mp4: Check the return value of ->truncate().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 26 Aug 2021 20:11:40 +0000 (22:11 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 6 Jun 2022 18:46:37 +0000 (20:46 +0200)
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.

aac_afh.c
mp4.c
mp4.h

index ae1e99dc9662095af7cc887173c85b9598dd7796..b45db477e0e80ddbe1f170446c92e2df99cdc9e1 100644 (file)
--- 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 9ed0fcbb4dfbfaa07b53893e7e021607a17636ad..0bddac9c2f512c4cf8a6e1ef0f6f3aed044b8a21 100644 (file)
--- 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 0775956bdff2fae0c2cbd8e432bdf94cbf6a9dcd..49c4be18a5929c9e79e091704e9ab2e4112cc22b 100644 (file)
--- 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;
 };