From e16b366d03ab803da51c06885e5642190e974052 Mon Sep 17 00:00:00 2001 From: Allen Winter Date: Sun, 5 May 2024 19:18:37 -0400 Subject: [PATCH] Add __attribute__((sentinel)) to all _vanew function declarations fixes: #604 --- scripts/mkderivedproperties.pl | 2 +- src/libical/CMakeLists.txt | 1 + src/libical/icalcomponent.h | 3 ++- src/libical/icalderivedproperty.h.in | 1 + src/libical/libical_sentinel.h | 23 +++++++++++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/libical/libical_sentinel.h diff --git a/scripts/mkderivedproperties.pl b/scripts/mkderivedproperties.pl index 7e1d9065b..c936fe28a 100644 --- a/scripts/mkderivedproperties.pl +++ b/scripts/mkderivedproperties.pl @@ -302,7 +302,7 @@ sub insert_code LIBICAL_ICAL_EXPORT $type icalproperty_get_${lc}(const icalproperty *prop);"; if ($include_vanew) { - print "\nLIBICAL_ICAL_EXPORT icalproperty *icalproperty_vanew_${lc}($type v, ...);\n"; + print "\nLIBICAL_ICAL_EXPORT LIBICAL_SENTINEL icalproperty *icalproperty_vanew_${lc}($type v, ...);\n"; } } diff --git a/src/libical/CMakeLists.txt b/src/libical/CMakeLists.txt index 370e26d32..aeff8b377 100644 --- a/src/libical/CMakeLists.txt +++ b/src/libical/CMakeLists.txt @@ -432,6 +432,7 @@ install(FILES icaltypes.h icalvalue.h libical_deprecated.h + libical_sentinel.h libical_ical_export.h pvl.h sspm.h diff --git a/src/libical/icalcomponent.h b/src/libical/icalcomponent.h index ac0828f02..1e04efc40 100644 --- a/src/libical/icalcomponent.h +++ b/src/libical/icalcomponent.h @@ -16,6 +16,7 @@ #define ICALCOMPONENT_H #include "libical_deprecated.h" +#include "libical_sentinel.h" #include "libical_ical_export.h" #include "icalenums.h" /* Defines icalcomponent_kind */ #include "icalproperty.h" @@ -51,7 +52,7 @@ LIBICAL_ICAL_EXPORT icalcomponent *icalcomponent_new_from_string(const char *str * * Make sure to pass NULL (not 0) as the final argument! */ -LIBICAL_ICAL_EXPORT icalcomponent *icalcomponent_vanew(icalcomponent_kind kind, ...); +LIBICAL_ICAL_EXPORT LIBICAL_SENTINEL icalcomponent *icalcomponent_vanew(icalcomponent_kind kind, ...); /** @brief Constructor */ diff --git a/src/libical/icalderivedproperty.h.in b/src/libical/icalderivedproperty.h.in index c5244dd84..e52492668 100644 --- a/src/libical/icalderivedproperty.h.in +++ b/src/libical/icalderivedproperty.h.in @@ -11,6 +11,7 @@ #ifndef ICALDERIVEDPROPERTY_H #define ICALDERIVEDPROPERTY_H +#include "libical_sentinel.h" #include "icalparameter.h" #include "icalderivedvalue.h" #include "icalrecur.h" diff --git a/src/libical/libical_sentinel.h b/src/libical/libical_sentinel.h new file mode 100644 index 000000000..7dd596d35 --- /dev/null +++ b/src/libical/libical_sentinel.h @@ -0,0 +1,23 @@ +/** + SPDX-FileCopyrightText: Allen Winter + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 +*/ + +#ifndef LIBICAL_SENTINEL_H +#define LIBICAL_SENTINEL_H + +/* sentinel attribute macro */ +#if defined(NO_SENTINEL_WARNINGS) +#define LIBICAL_SENTINEL +#else +#if !defined(LIBICAL_SENTINEL) +#if defined(__GNUC__) || defined(__clang__) +#define LIBICAL_SENTINEL __attribute__((sentinel)) +#else +/* sentinel attributes are unknown to MSVC */ +#define LIBICAL_SENTINEL +#endif +#endif +#endif + +#endif