From 7ed3e1d92722a0b4ec4e60231db71dbc7c849c75 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Fri, 7 Feb 2020 10:06:01 +0530 Subject: [PATCH] feat(userspace): Add `BAN_ALTERNATIVE` macro to `banned.h`. BAN_ALTERNATIVE is same as BAN but the message also provides an alternative function that the user could use instead of the banned function. Fixes #1035 Signed-off-by: Vaibhav --- userspace/engine/banned.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/userspace/engine/banned.h b/userspace/engine/banned.h index 41690220..85dd6f34 100644 --- a/userspace/engine/banned.h +++ b/userspace/engine/banned.h @@ -21,14 +21,18 @@ limitations under the License. // function is used. #define BAN(function) using_##function##_is_banned +// BAN_ALTERNATIVE is same as BAN but the message also provides an alternative +// function that the user could use instead of the banned function. +#define BAN_ALTERNATIVE(function, alternative) using_##function##_is_banned__use_##alternative##_instead + #undef strcpy #define strcpy(a, b) BAN(strcpy) #undef vsprintf -#define vsprintf(a, b, c) BAN(vsprintf) +#define vsprintf(a, b, c) BAN_ALTERNATIVE(vsprintf, vsnprintf) #undef sprintf -#define sprintf(a, b, ...) BAN(sprintf) +#define sprintf(a, b, ...) BAN_ALTERNATIVE(sprintf, snprintf) #undef strcat #define strcat(a, b) BAN(strcat) @@ -40,7 +44,7 @@ limitations under the License. #define strncpy(a, b, c) BAN(strncpy) #undef swprintf -#define swprintf(a, b, c, ...) BAN(swprintf) +#define swprintf(a, b, c, ...) BAN_ALTERNATIVE(swprintf, snprintf) #undef vswprintf -#define vswprintf(a, b, c, d) BAN(vswprintf) +#define vswprintf(a, b, c, d) BAN_ALTERNATIVE(vswprintf, vsnprintf)