diff options
author | Sergei Golubchik <serg@mariadb.org> | 2018-03-29 23:23:19 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-04-10 13:12:36 +0200 |
commit | 479bd5a6fe9966397ad40ab0a997b4d1901d8805 (patch) | |
tree | 0731acb9cbe2534bbff71532b19920f5b7324487 /include/m_string.h | |
parent | 7dcf1b50493ce7670c21d9dfce25a6b5003ce3ea (diff) | |
download | mariadb-git-479bd5a6fe9966397ad40ab0a997b4d1901d8805.tar.gz |
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.
Diffstat (limited to 'include/m_string.h')
-rw-r--r-- | include/m_string.h | 2 |
1 files changed, 1 insertions, 1 deletions
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 |