[FFmpeg-devel] [PATCH v1 4/4] avformat/hlsenc: use av_asprintf()

Nicolas George george at nsup.org
Wed Apr 8 17:48:18 EEST 2020


Steven Liu (12020-04-08):
> I cannot get the mean of BPrint where should or when should use it, maybe you can introduce it,
> I always think BPrint is used to instead of av_[a]sprintf, 
> because I saw mkver submit 3 patches to modify from snprintf to BPrint

BPrint brings three benefits:

- It keeps track of the string length. It is therefore useful when you
  have several snprintf(). If you have only one, this benefit is
  negated.

- It switches to dynamic allocation if the buffer is too small. If your
  string does not have a bounded size and keeping it entirely is
  important, then replacing a buffer with an arbitrary high limit with
  BPrint is useful.

- Before switching to dynamic allocation, it uses a local buffer in the
  structure (probably on stack). If the string does not need to outlive
  its creation very far, it works. If we need to keep the string, a
  dynamic allocation is necessary anyway.

For this case: (1) there is only one snprintf(), (2) we don't use a
fixed-size buffer and (3) we'll keep the string.

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/20200408/d2473e76/attachment.sig>


More information about the ffmpeg-devel mailing list