Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2022-09-14 11:40:09 +0300
committerMartin Storsjö <martin@martin.st>2022-09-14 15:59:19 +0300
commit08c708015ec372b6c28d341cba7bbc86843cc17b (patch)
treedbf512e23c33ac8d89dbf6eb80cfa49364a96a26
parent128a0d8992458698a05fbd4d1bba55a5b7e5cdf4 (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.
-rw-r--r--tools/input/input.c5
-rw-r--r--tools/output/output.c5
2 files changed, 6 insertions, 4 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;
diff --git a/tools/output/output.c b/tools/output/output.c
index cf66d2e..f8910d4 100644
--- a/tools/output/output.c
+++ b/tools/output/output.c
@@ -46,6 +46,7 @@ struct MuxerContext {
unsigned fps[2];
const char *filename;
int framenum;
+ uint64_t priv_data[];
};
extern const Muxer null_muxer;
@@ -123,12 +124,12 @@ int output_open(MuxerContext **const c_out,
}
}
- if (!(c = malloc(sizeof(MuxerContext) + impl->priv_data_size))) {
+ if (!(c = malloc(offsetof(MuxerContext, priv_data) + impl->priv_data_size))) {
fprintf(stderr, "Failed to allocate memory\n");
return DAV1D_ERR(ENOMEM);
}
c->impl = impl;
- c->data = (MuxerPriv *) &c[1];
+ c->data = (MuxerPriv *) c->priv_data;
int have_num_pattern = 0;
for (const char *ptr = filename ? strchr(filename, '%') : NULL;
!have_num_pattern && ptr; ptr = strchr(ptr, '%'))