From: Hallvard Furuseth Date: Fri, 17 Oct 2008 18:43:10 +0000 (+0000) Subject: ITS#5747: Only use C99 flexible array member when supported X-Git-Tag: ACLCHECK_0~1236 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=036e7dac5901d564f171167e3fe0c341a46c1d16;p=openldap ITS#5747: Only use C99 flexible array member when supported --- diff --git a/servers/slapd/overlays/collect.c b/servers/slapd/overlays/collect.c index 4852022f95..680fb9b59f 100644 --- a/servers/slapd/overlays/collect.c +++ b/servers/slapd/overlays/collect.c @@ -42,11 +42,20 @@ * is no effect. If no attribute was configured, there is no effect. */ +/* Use C99 flexible array member if supported, C89 "struct hack" otherwise. */ +#define FLEXIBLE_STRUCT_SIZE(stype, mtype, mcount) \ + (sizeof(stype) + sizeof(mtype) * ((mcount) - (0 FLEXIBLE_ARRAY_MEMBER))) +#if __STDC_VERSION__>=199901L || (defined __GNUC__ && !defined __STRICT_ANSI__) +#define FLEXIBLE_ARRAY_MEMBER +#else +#define FLEXIBLE_ARRAY_MEMBER +1 +#endif + typedef struct collect_info { struct collect_info *ci_next; struct berval ci_dn; int ci_ad_num; - AttributeDescription *ci_ad[]; + AttributeDescription *ci_ad[FLEXIBLE_ARRAY_MEMBER]; } collect_info; /* @@ -175,8 +184,8 @@ collect_cf( ConfigArgs *c ) } /* allocate config info with room for attribute array */ - ci = ch_malloc( sizeof( collect_info ) + - ( sizeof (AttributeDescription *) * (count + 1))); + ci = ch_malloc( FLEXIBLE_STRUCT_SIZE( collect_info, + AttributeDescription *, count + 1 )); /* validate and normalize dn */ ber_str2bv( c->argv[1], 0, 0, &bv );