From bf684e958352b7078f3b685c2f49bd5122cba6ae Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 26 Aug 2023 12:32:29 -0500 Subject: [PATCH] Base: Add static_assert for keyword array size > 0 --- src/Base/PyWrapParseTupleAndKeywords.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Base/PyWrapParseTupleAndKeywords.h b/src/Base/PyWrapParseTupleAndKeywords.h index 3b1d151b9b..9a5400ccc7 100644 --- a/src/Base/PyWrapParseTupleAndKeywords.h +++ b/src/Base/PyWrapParseTupleAndKeywords.h @@ -44,6 +44,8 @@ namespace Base { const std::array keywords, ...) { + static_assert(arraySize > 0, "keywords array must have at least a single nullptr in it"); + // NOTE: This code is from getargs.c in the Python source code (modified to use the public interface at // PyArg_VaParseTupleAndKeywords and to return a bool). va_list va; // NOLINT @@ -51,7 +53,6 @@ namespace Base { if ((args == nullptr || !PyTuple_Check(args)) || (kw != nullptr && !PyDict_Check(kw)) || format == nullptr || - keywords.empty() || // It must at least have a single nullptr in it (TODO: compilation error instead) keywords.back() != nullptr) // It must END with a nullptr { PyErr_BadInternalCall();