diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-04 11:01:01 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-04 11:01:01 +0000 |
commit | 6aef8ee8201f0d6167438a64d13efa3790069175 (patch) | |
tree | 035e9959653a060a555db1a024c3ffae39471b1c | |
parent | ac6cc76bab943b9b3b463d9c0bf1c5395e36d46b (diff) |
Use GCC's __builtin_types_compatible_p()
-rw-r--r-- | src/htssafe.h | 15 |
1 files 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 @@ -80,15 +80,26 @@ static void abortf_(const char *exp, const char *file, int line) { } /** + * 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" */ |