The below C program compiles and runs just fine on GCC 4.9 with -std=c99 with just one warning(warning: assignment makes pointer from integer without a cast) when the strdup is called.
On GCC 6 and above, the same code compiles fine but generates segmentation fault when compiled with -std=c99
Thanks, Dave
#include <stdio.h>
#include <string.h>
typedef enum {
POOL_ACCOUNTING
} pool_name_e;
typedef struct pool_attributes {
int pool_size;
char *conn_string;
} pool_attributes_t;
typedef struct connection {
int conn_index;
pool_name_e pool_name;
pool_attributes_t *pool_attributes;
} connection_t;
typedef struct conn_pool {
pool_attributes_t pool_attributes;
} conn_pool_t;
struct {
conn_pool_t Accounting;
conn_pool_t Support;
} manager;
int main( ) {
char *value="server=test.local user=test";
manager.Accounting.pool_attributes.conn_string=strdup(value);
printf("%s\n",manager.Accounting.pool_attributes.conn_string);
return 0;
}