Add CHECK/SUINT code
authorMichael Niedermayer <michael@niedermayer.cc>
Mon, 20 Feb 2017 18:34:54 +0000 (19:34 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 20 May 2017 01:41:32 +0000 (03:41 +0200)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 4614bf2caf67a89c2d833b3368f325eab54582bc)
(cherry picked from commit e8d4eacc07c61ae24f48451073a2620d8d257d33)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 3f2a09a43f6fade53227804459e6babb1c7248b3)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavutil/internal.h

index 047f742..5a7a29d 100644 (file)
 #    define NDEBUG
 #endif
 
+#if defined(DEBUG) && !defined(CHECKED)
+#    define CHECKED
+#endif
+
 #include <limits.h>
 #include <stdint.h>
 #include <stddef.h>
@@ -256,6 +260,16 @@ void avpriv_request_sample(void *avc,
 #   define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
 #endif
 
+// For debuging we use signed operations so overflows can be detected (by ubsan)
+// For production we use unsigned so there are no undefined operations
+#ifdef CHECKED
+#define SUINT   int
+#define SUINT32 int32_t
+#else
+#define SUINT   unsigned
+#define SUINT32 uint32_t
+#endif
+
 /**
  * A wrapper for open() setting O_CLOEXEC.
  */