[FFmpeg-devel] [PATCH] avutil/mem: use C11 aligned_malloc()

Rémi Denis-Courmont remi at remlab.net
Sun Feb 18 20:35:53 EET 2024


Le sunnuntaina 18. helmikuuta 2024, 18.27.35 EET Andreas Rheinhardt a écrit :
> 1. The function is called aligned_alloc (how did you test this?).
> 2. C11: "The value of alignment shall be a valid alignment supported by
> the implementation and the value of size shall be an integral multiple
> of alignment."
> a) To use this, you would have to round size upwards; but this will make
> sanitiziers more lenient.
> b) If ALIGN is just not supported by the implementation, then everything
> is UB in C11.

The letter of the specification is that all alignments of types defined in the 
specification must be supported and other "may" be supported. The intent is 
clearly that all relevant alignments on the target platform are supported.

FFmpeg assumes that alignment 16, 32 and 64 are supported already anyhow, so 
this would not be introducing any *new* UB. In this respect, FFmpeg is doing 
UB on practically all platforms other than x86, which seems to be the only 
platform to need alignment of 32 and 64 bytes for anything.

IMO, FFmpeg should not use custom alignments beyond `alignof(max_align_t)` 
unless they are specifically needed on the given platform, but that's a 
potentially tedious clean-up task with zero practical gains.

> 3. What's the advantage of this patch anyway?

In theory, `aligned_alloc()` (not `aligned_malloc()`) supports alignment of 1 
and any legal value until `sizeof(void*)`, *unlike* `posix_memalign()`. But 
since you can just as well use `malloc()` for that purpose, that is not a real 
advantage.

-- 
レミ・デニ-クールモン
http://www.remlab.net/





More information about the ffmpeg-devel mailing list