mirror of https://git.ffmpeg.org/ffmpeg.git
avformat/avformat: Avoid av_strdup(NULL)
It is not documented to be safe. Also copy these lists in a more generic manner. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
569ad285a5
commit
ad9f644505
|
@ -875,20 +875,28 @@ const AVCodec *ff_find_decoder(AVFormatContext *s, const AVStream *st,
|
||||||
|
|
||||||
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
|
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
|
||||||
{
|
{
|
||||||
|
#define OFF(field) offsetof(AVFormatContext, field)
|
||||||
|
static const unsigned offsets[] = {
|
||||||
|
OFF(codec_whitelist), OFF(format_whitelist),
|
||||||
|
OFF(protocol_whitelist), OFF(protocol_blacklist),
|
||||||
|
};
|
||||||
|
#undef OFF
|
||||||
av_assert0(!dst->codec_whitelist &&
|
av_assert0(!dst->codec_whitelist &&
|
||||||
!dst->format_whitelist &&
|
!dst->format_whitelist &&
|
||||||
!dst->protocol_whitelist &&
|
!dst->protocol_whitelist &&
|
||||||
!dst->protocol_blacklist);
|
!dst->protocol_blacklist);
|
||||||
dst-> codec_whitelist = av_strdup(src->codec_whitelist);
|
for (unsigned i = 0; i < FF_ARRAY_ELEMS(offsets); i++) {
|
||||||
dst->format_whitelist = av_strdup(src->format_whitelist);
|
const char *src_str = *(char *const*)((const char*)src + offsets[i]);
|
||||||
dst->protocol_whitelist = av_strdup(src->protocol_whitelist);
|
|
||||||
dst->protocol_blacklist = av_strdup(src->protocol_blacklist);
|
if (src_str) {
|
||||||
if ( (src-> codec_whitelist && !dst-> codec_whitelist)
|
char *dst_str = av_strdup(src_str);
|
||||||
|| (src-> format_whitelist && !dst-> format_whitelist)
|
if (!dst_str) {
|
||||||
|| (src->protocol_whitelist && !dst->protocol_whitelist)
|
av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
|
||||||
|| (src->protocol_blacklist && !dst->protocol_blacklist)) {
|
return AVERROR(ENOMEM);
|
||||||
av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
|
}
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
|
*(char **)((char*)dst + offsets[i]) = dst_str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue