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.
This commit is contained in:
Norihiro Kamae 2023-04-09 08:55:43 +09:00 committed by Jim
parent 6e25b3198a
commit 593fb3d12d
2 changed files with 13 additions and 9 deletions

View file

@ -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 <stddef.h>

View file

@ -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) \