diff options
author | Martin Storsjö <martin@martin.st> | 2022-09-14 11:40:09 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2022-09-14 15:59:19 +0300 |
commit | 08c708015ec372b6c28d341cba7bbc86843cc17b (patch) | |
tree | dbf512e23c33ac8d89dbf6eb80cfa49364a96a26 /tools/input | |
parent | 128a0d8992458698a05fbd4d1bba55a5b7e5cdf4 (diff) |
tools: Allocate the priv structs with proper alignment
Previously, they could be allocated with any random alignment
matching the end of the MuxerContext/DemuxerContext. The
priv structs themselves can have members that require specific
alignment, or at least the default alignment of malloc()/calloc()
(which is sufficient for native types such as uint64_t and
doubles).
This fixes crashes in some arm builds, where GCC (correctly) wants
to use 64 bit aligned stores to write to MD5Context.
Diffstat (limited to 'tools/input')
-rw-r--r-- | tools/input/input.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/input/input.c b/tools/input/input.c index 4756648..2dfaa97 100644 --- a/tools/input/input.c +++ b/tools/input/input.c @@ -41,6 +41,7 @@ struct DemuxerContext { DemuxerPriv *data; const Demuxer *impl; + uint64_t priv_data[]; }; extern const Demuxer ivf_demuxer; @@ -109,12 +110,12 @@ int input_open(DemuxerContext **const c_out, } } - if (!(c = calloc(1, sizeof(DemuxerContext) + impl->priv_data_size))) { + if (!(c = calloc(1, offsetof(DemuxerContext, priv_data) + impl->priv_data_size))) { fprintf(stderr, "Failed to allocate memory\n"); return DAV1D_ERR(ENOMEM); } c->impl = impl; - c->data = (DemuxerPriv *) &c[1]; + c->data = (DemuxerPriv *) c->priv_data; if ((res = impl->open(c->data, filename, fps, num_frames, timebase)) < 0) { free(c); return res; |