From 3cde7a1731d001521eb3552306d0fd12c11018e6 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Fri, 15 May 2020 21:46:03 +0200 Subject: [PATCH] Add protection for use of oplist within a container oplist --- m-funcobj.h | 13 +++++++++++-- m-tuple.h | 10 +++++++++- m-variant.h | 10 +++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/m-funcobj.h b/m-funcobj.h index 5f4bc528..99f7b5e0 100644 --- a/m-funcobj.h +++ b/m-funcobj.h @@ -62,7 +62,7 @@ * FUNC_OBJ_INS_OPLIST(name, oplist of the attr1, ...) */ #define FUNC_OBJ_INS_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__)(FUNC_OBJ_INS_NO_ATTR_OPLIST, FUNC_OBJ_INS_ATTR_OPLIST)( __VA_ARGS__) + M_IF_NARGS_EQ1(__VA_ARGS__)(FUNC_OBJ_INS_NO_ATTR_OPLIST, FUNC_OBJ_INS_ATTR_OPLIST_P1)( __VA_ARGS__) @@ -90,7 +90,16 @@ INIT(M_C(name,_init)) \ ) -#define FUNC_OBJ_INS_ATTR_OPLIST(name, ...) \ +/* Validate the oplist before going further */ +#define FUNC_OBJ_INS_ATTR_OPLIST_P1(name, ...) \ + M_IF(M_REDUCE(M_OPLIST_P, M_AND, __VA_ARGS__))(FUNC_OBJ_INS_ATTR_OPLIST_P3, FUNC_OBJ_INS_ATTR_OPLIST_FAILURE)(name, __VA_ARGS__) + +/* Prepare a clean compilation failure */ +#define FUNC_OBJ_INS_ATTR_OPLIST_FAILURE(name, ...) \ + M_LIB_ERROR(ONE_ARGUMENT_OF_FUNC_OBJ_INS_OPLIST_IS_NOT_AN_OPLIST, name, __VA_ARGS__) + +/* Define at least the oplist */ +#define FUNC_OBJ_INS_ATTR_OPLIST_P3(name, ...) \ (NAME(name), TYPE(M_C(name, _t)), \ INIT_WITH(M_C(name, _init_with)), \ CLEAR(M_C(name, _clear)), \ diff --git a/m-tuple.h b/m-tuple.h index be709dbf..cbdcba44 100644 --- a/m-tuple.h +++ b/m-tuple.h @@ -530,7 +530,15 @@ namespace m_tuple { // deferred #define TUPLEI_OPLIST_P1(arg) TUPLEI_OPLIST_P2 arg -#define TUPLEI_OPLIST_P2(name, ...) \ +/* Validate the oplist before going further */ +#define TUPLEI_OPLIST_P2(name, ...) \ + M_IF(M_REDUCE(M_OPLIST_P, M_AND, __VA_ARGS__))(TUPLEI_OPLIST_P3, TUPLEI_OPLIST_FAILURE)(name, __VA_ARGS__) + +/* Prepare a clean compilation failure */ +#define TUPLEI_OPLIST_FAILURE(name, ...) \ + M_LIB_ERROR(ONE_ARGUMENT_OF_TUPLE_OPLIST_IS_NOT_AN_OPLIST, name, __VA_ARGS__) + +#define TUPLEI_OPLIST_P3(name, ...) \ (M_IF_METHOD_ALL(INIT, __VA_ARGS__)(INIT(M_C(name,_init)),), \ INIT_SET(M_C(name, _init_set)), \ INIT_WITH(M_C(name, _init_set2)), \ diff --git a/m-variant.h b/m-variant.h index be45ca52..b6e9067d 100644 --- a/m-variant.h +++ b/m-variant.h @@ -609,7 +609,15 @@ // deferred #define VARIANTI_OPLIST_P1(arg) VARIANTI_OPLIST_P2 arg -#define VARIANTI_OPLIST_P2(name, ...) \ +/* Validate the oplist before going further */ +#define VARIANTI_OPLIST_P2(name, ...) \ + M_IF(M_REDUCE(M_OPLIST_P, M_AND, __VA_ARGS__))(VARIANTI_OPLIST_P3, VARIANTI_OPLIST_FAILURE)(name, __VA_ARGS__) + +/* Prepare a clean compilation failure */ +#define VARIANTI_OPLIST_FAILURE(name, ...) \ + M_LIB_ERROR(ONE_ARGUMENT_OF_VARIANT_OPLIST_IS_NOT_AN_OPLIST, name, __VA_ARGS__) + +#define VARIANTI_OPLIST_P3(name, ...) \ (INIT(M_C(name,_init)), \ INIT_SET(M_C(name, _init_set)), \ SET(M_C(name,_set)), \