From ca73b2f465f6a305e913b5327eb95d8021e243e1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 4 Feb 2019 05:41:40 -0600 Subject: [PATCH] Add static assert to catch errors in COPY(a,b) --- Marlin/src/core/macros.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 1c57d88c86..f1b2550c61 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -152,7 +152,10 @@ #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+') #define COUNT(a) (sizeof(a)/sizeof(*a)) #define ZERO(a) memset(a,0,sizeof(a)) -#define COPY(a,b) memcpy(a,b,MIN(sizeof(a),sizeof(b))) +#define COPY(a,b) do{ \ + static_assert(sizeof(a[0]) == sizeof(b[0]), "COPY: '" STRINGIFY(a) "' and '" STRINGIFY(b) "' types (sizes) don't match!"); \ + memcpy(&a[0],&b[0],MIN(sizeof(a),sizeof(b))); \ + }while(0) // Macros for initializing arrays #define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }