diff --git a/libobs/util/c99defs.h b/libobs/util/c99defs.h index 3d6a32a45..a05a1cdfc 100644 --- a/libobs/util/c99defs.h +++ b/libobs/util/c99defs.h @@ -55,25 +55,20 @@ #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 diff --git a/libobs/util/darray.h b/libobs/util/darray.h index db8a77d42..2b308eb22 100644 --- a/libobs/util/darray.h +++ b/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); 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; } @@ -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) #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) +#endif #ifdef ENABLE_DARRAY_TYPE_TEST #define da_push_back_array(dst, src_array, n) \