Преглед на файлове

libobs: Remove newly introduced PRAGMA_WARN_STRINGOP_OVERFLOW macro

The macro PRAGMA_WARN_STRINGOP_OVERFLOW was introduced to suppress a
warning -Wstringop-overflow caused by a macro da_push_back_new calling
darray_push_back_new.
Extract the function in the macro to avoid the warning.
This will also enables checking the type check of the returned pointer.
Norihiro Kamae преди 2 години
родител
ревизия
593fb3d12d
променени са 2 файла, в които са добавени 13 реда и са изтрити 9 реда
  1. 0 5
      libobs/util/c99defs.h
  2. 13 4
      libobs/util/darray.h

+ 0 - 5
libobs/util/c99defs.h

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

+ 13 - 4
libobs/util/darray.h

@@ -207,11 +207,7 @@ static inline void *darray_push_back_new(const size_t element_size,
 	darray_ensure_capacity(element_size, dst, ++dst->num);
 	darray_ensure_capacity(element_size, dst, ++dst->num);
 
 
 	last = darray_end(element_size, dst);
 	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);
 	memset(last, 0, element_size);
-	PRAGMA_WARN_POP
 	return last;
 	return last;
 }
 }
 
 
@@ -542,7 +538,20 @@ static inline void darray_swap(const size_t element_size, struct darray *dst,
 #define da_push_back(v, item) darray_push_back(sizeof(*v.array), &v.da, item)
 #define da_push_back(v, item) darray_push_back(sizeof(*v.array), &v.da, item)
 #endif
 #endif
 
 
+#ifdef __GNUC__
+/* GCC 12 with -O2 generates a warning -Wstringop-overflow in da_push_back_new,
+ * which could be false positive. Extract the macro here to avoid the warning.
+ */
+#define da_push_back_new(v)                                                  \
+	({                                                                   \
+		__typeof__(v) *d = &(v);                                     \
+		darray_ensure_capacity(sizeof(*d->array), &d->da, ++d->num); \
+		memset(&d->array[d->num - 1], 0, sizeof(*d->array));         \
+		&d->array[d->num - 1];                                       \
+	})
+#else
 #define da_push_back_new(v) darray_push_back_new(sizeof(*v.array), &v.da)
 #define da_push_back_new(v) darray_push_back_new(sizeof(*v.array), &v.da)
+#endif
 
 
 #ifdef ENABLE_DARRAY_TYPE_TEST
 #ifdef ENABLE_DARRAY_TYPE_TEST
 #define da_push_back_array(dst, src_array, n)                                  \
 #define da_push_back_array(dst, src_array, n)                                  \