[FFmpeg-devel] [PATCH] avutil: add av_memcpy() to avoid undefined behavior with NULL, NULL, 0

Michael Niedermayer michael at niedermayer.cc
Tue Jul 2 23:56:30 EEST 2019


Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 doc/APIchanges      |  3 +++
 libavutil/mem.h     | 13 +++++++++++++
 libavutil/version.h |  2 +-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index b5fadc2a48..65b8ed74ad 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2019-07-XX - XXXXXXXXXX - lavu 56.31.100 - mem.h
+  Add av_memcpy()
+
 2019-06-21 - XXXXXXXXXX - lavu 56.30.100 - frame.h
   Add FF_DECODE_ERROR_DECODE_SLICES
 
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5fb1a02dd9..a35230360d 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -506,6 +506,19 @@ void *av_memdup(const void *p, size_t size);
  */
 void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
 
+/**
+ * memcpy() implementation without a NULL pointer special case
+ *
+ * @param dst  Destination buffer
+ * @param src  Source buffer
+ * @param cnt  Number of bytes to copy; must be >= 0
+ */
+static inline void av_memcpy(void *dst, const void *src, size_t cnt)
+{
+    if (cnt)
+        memcpy(dst, src, cnt);
+}
+
 /**
  * @}
  */
diff --git a/libavutil/version.h b/libavutil/version.h
index e16b93e877..24ca8ab7db 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  30
+#define LIBAVUTIL_VERSION_MINOR  31
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.22.0



More information about the ffmpeg-devel mailing list