diff mbox series

[FFmpeg-devel,2/2] avformat/aadec: Replace strncpy by av_strlcpy

Message ID 20210302091657.473380-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 491a30c79cf7e1fa7e32aeb4968a8c63af6e0534
Headers show
Series [FFmpeg-devel,1/2] avformat/aadec: Use smaller scope for variables, remove initializations
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 2, 2021, 9:16 a.m. UTC
While this usage of strncpy is correct, said function nevertheless has
the disadvantage of not automatically ensuring that the destination
string is zero-terminated. So av_strlcpy should be preferred.
This also removes a -Wstringop-truncation warning from GCC (it doesn't
matter whether the buffer is truncated, as long as it can fit all
the names of the supported codecs).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/aadec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavformat/aadec.c b/libavformat/aadec.c
index b1e93ea072..e88cdb89df 100644
--- a/libavformat/aadec.c
+++ b/libavformat/aadec.c
@@ -114,7 +114,7 @@  static int aa_read_header(AVFormatContext *s)
         avio_get_str(pb, nval, val, sizeof(val));
         if (!strcmp(key, "codec")) {
             av_log(s, AV_LOG_DEBUG, "Codec is <%s>\n", val);
-            strncpy(codec_name, val, sizeof(codec_name) - 1);
+            av_strlcpy(codec_name, val, sizeof(codec_name));
         } else if (!strcmp(key, "HeaderSeed")) {
             av_log(s, AV_LOG_DEBUG, "HeaderSeed is <%s>\n", val);
             header_seed = atoi(val);