From 479bd5a6fe9966397ad40ab0a997b4d1901d8805 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 29 Mar 2018 23:23:19 +0200 Subject: [PATCH] improve strmake_buf() to detect wrong usage reliably strmake_buf() macro should only be used with char[] arrays, and never with char* pointers. To distinguish between the two we create a new variable of the same type and initialize it using array initializer, this causes compilation failure with pointers. The variable is unused and will be removed by the compiler. It's enough to do this check only with gcc, so it doesn't have to be portable. --- include/m_string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/m_string.h b/include/m_string.h index 04f4721b6fb..d50da8770c3 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -99,7 +99,7 @@ extern char *strmake(char *dst,const char *src,size_t length); #define strmake_buf(D,S) strmake(D, S, sizeof(D) - 1) #else #define strmake_buf(D,S) ({ \ - compile_time_assert(sizeof(D) != sizeof(char*)); \ + typeof (D) __x __attribute__((unused)) = { 2 }; \ strmake(D, S, sizeof(D) - 1); \ }) #endif