From 6aef8ee8201f0d6167438a64d13efa3790069175 Mon Sep 17 00:00:00 2001 From: Xavier Roche Date: Sun, 4 May 2014 11:01:01 +0000 Subject: Use GCC's __builtin_types_compatible_p() --- src/htssafe.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/htssafe.h b/src/htssafe.h index 6b53ce7..dc3382e 100644 --- a/src/htssafe.h +++ b/src/htssafe.h @@ -79,16 +79,27 @@ static void abortf_(const char *exp, const char *file, int line) { abort(); } +/** + * Check wether 'VAR' is of type char[]. + */ +#ifdef __GNUC__ +/* Note: char[] and const char[] are compatible */ +#define HTS_IS_CHAR_BUFFER(VAR) ( __builtin_types_compatible_p ( typeof (VAR), char[] ) ) +#else +#define HTS_IS_CHAR_BUFFER(VAR) ( sizeof(VAR) != sizeof(char*) ) +#endif +#define HTS_IS_NOT_CHAR_BUFFER(VAR) ( ! HTS_IS_CHAR_BUFFER(VAR) ) + /** * Append at most N characters from "B" to "A". * If "A" is a char[] variable whose size is not sizeof(char*), then the size * is assumed to be the capacity of this array. */ #define strncatbuff(A, B, N) \ - ( sizeof(A) == sizeof(char*) \ + ( HTS_IS_NOT_CHAR_BUFFER(A) \ ? strncat(A, B, N) \ : strncat_safe_(A, sizeof(A), B, \ - sizeof(B) == sizeof(char*) ? (size_t) -1 : sizeof(B), N, \ + HTS_IS_NOT_CHAR_BUFFER(B) ? (size_t) -1 : sizeof(B), N, \ "overflow while copying '" #B "' to '"#A"'", __FILE__, __LINE__) ) /* note: "size_t is an unsigned integral type" */ -- cgit v1.2.3