Browse Source

libobs: Calm stringop-overflow warning on GCC

Those warnings appeared with GCC 12 with -O2, those are potentially
created by regression from GCC.
tytan652 3 years ago
parent
commit
678b0287e6
2 changed files with 9 additions and 0 deletions
  1. 5 0
      libobs/util/c99defs.h
  2. 4 0
      libobs/util/darray.h

+ 5 - 0
libobs/util/c99defs.h

@@ -55,20 +55,25 @@
 #define PRAGMA_WARN_PUSH __pragma(warning(push))
 #define PRAGMA_WARN_POP __pragma(warning(pop))
 #define PRAGMA_WARN_DEPRECATION
+#define PRAGMA_WARN_STRINGOP_OVERFLOW
 #elif defined(__clang__)
 #define PRAGMA_WARN_PUSH _Pragma("clang diagnostic push")
 #define PRAGMA_WARN_POP _Pragma("clang diagnostic pop")
 #define PRAGMA_WARN_DEPRECATION \
 	_Pragma("clang diagnostic warning \"-Wdeprecated-declarations\"")
+#define PRAGMA_WARN_STRINGOP_OVERFLOW
 #elif defined(__GNUC__)
 #define PRAGMA_WARN_PUSH _Pragma("GCC diagnostic push")
 #define PRAGMA_WARN_POP _Pragma("GCC diagnostic pop")
 #define PRAGMA_WARN_DEPRECATION \
 	_Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
+#define PRAGMA_WARN_STRINGOP_OVERFLOW \
+	_Pragma("GCC diagnostic warning \"-Wstringop-overflow\"")
 #else
 #define PRAGMA_WARN_PUSH
 #define PRAGMA_WARN_POP
 #define PRAGMA_WARN_DEPRECATION
+#define PRAGMA_WARN_STRINGOP_OVERFLOW
 #endif
 
 #include <stddef.h>

+ 4 - 0
libobs/util/darray.h

@@ -207,7 +207,11 @@ static inline void *darray_push_back_new(const size_t element_size,
 	darray_ensure_capacity(element_size, dst, ++dst->num);
 
 	last = darray_end(element_size, dst);
+	PRAGMA_WARN_PUSH
+	// NOTE: Those warning could be false positive from GCC 12 with -O2
+	PRAGMA_WARN_STRINGOP_OVERFLOW
 	memset(last, 0, element_size);
+	PRAGMA_WARN_POP
 	return last;
 }