Commit 73c02ec4 authored by Rusty Russell's avatar Rusty Russell

str: make sure STR_MAX_CHARS gives a constant expression.

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 97ac5832
...@@ -94,7 +94,7 @@ size_t strcount(const char *haystack, const char *needle); ...@@ -94,7 +94,7 @@ size_t strcount(const char *haystack, const char *needle);
#if HAVE_TYPEOF #if HAVE_TYPEOF
/* Only a simple type can have 0 assigned, so test that. */ /* Only a simple type can have 0 assigned, so test that. */
#define STR_MAX_CHARS_TCHECK_(type_or_expr) \ #define STR_MAX_CHARS_TCHECK_(type_or_expr) \
({ typeof(type_or_expr) x = 0; (void)x; 0; }) (sizeof(({ typeof(type_or_expr) x = 0; x; }))*0)
#else #else
#define STR_MAX_CHARS_TCHECK_(type_or_expr) 0 #define STR_MAX_CHARS_TCHECK_(type_or_expr) 0
#endif #endif
......
#include <ccan/str/str.h>
int main(void)
{
static char str[STR_MAX_CHARS(int)];
return str[0] ? 0 : 1;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment