From 678b0287e6558de97e9a819e6c3d3049ac93ca51 Mon Sep 17 00:00:00 2001 From: tytan652 Date: Thu, 28 Jul 2022 11:09:00 +0200 Subject: [PATCH] libobs: Calm stringop-overflow warning on GCC Those warnings appeared with GCC 12 with -O2, those are potentially created by regression from GCC. --- libobs/util/c99defs.h | 5 +++++ libobs/util/darray.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/libobs/util/c99defs.h b/libobs/util/c99defs.h index a05a1cdfc..3d6a32a45 100644 --- a/libobs/util/c99defs.h +++ b/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 diff --git a/libobs/util/darray.h b/libobs/util/darray.h index b18d86614..db8a77d42 100644 --- a/libobs/util/darray.h +++ b/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; }