[FFmpeg-devel] [PATCH] avformat/protocols: check protocol name before foreach

Nicolas George george at nsup.org
Fri Jan 31 17:24:12 EET 2020


Liu Steven (12020-01-31):
> Just more safe than without check.

This is a mistake, a common one: this is not safer, it is less: the
caller has the incorrect assumption that their pointer is not NULL, and
you are letting them keep it, and even in some extents validating it.

> I think if it return -EINVAL maybe better than NULL, is it?

If it was possible (you accurately noticed that not), it would be
actually worse because it introduce a extra case for something that is
not supposed to happen in the first place.

Remember, FFmpeg is programmed in C, not Java or Python: when the
programmers do something stupid, like dividing by 0 or dereferencing
NULL, the program crashes: this is the correct behavior.

Unless there is a useful semantic to give to the NULL case, crashing
immediately is the right behavior. And saying the user "the protocol you
specified does not exist" when the issue is they did not specify a
protocol is not a useful semantic.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200131/f7a72629/attachment.sig>


More information about the ffmpeg-devel mailing list