From: Kirill Isakov Date: Mon, 28 Mar 2022 15:38:31 +0000 (+0600) Subject: Disable function attributes on unsupported compilers X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=6075fb8c185d0461070a9f16288e9d3673708735;p=tinc Disable function attributes on unsupported compilers --- diff --git a/src/cipher.h b/src/cipher.h index 966a8640..99751665 100644 --- a/src/cipher.h +++ b/src/cipher.h @@ -38,7 +38,7 @@ typedef struct cipher cipher_t; -extern cipher_t *cipher_alloc(void) __attribute__((__malloc__)); +extern cipher_t *cipher_alloc(void) ATTR_MALLOC; extern void cipher_free(cipher_t **cipher); extern bool cipher_open_by_name(cipher_t *cipher, const char *name); extern bool cipher_open_by_nid(cipher_t *cipher, int nid); @@ -46,10 +46,10 @@ extern void cipher_close(cipher_t *cipher); extern size_t cipher_keylength(const cipher_t *cipher); extern size_t cipher_blocksize(const cipher_t *cipher); extern uint64_t cipher_budget(const cipher_t *cipher); -extern bool cipher_set_key(cipher_t *cipher, void *key, bool encrypt) __attribute__((__warn_unused_result__)); -extern bool cipher_set_key_from_rsa(cipher_t *cipher, void *rsa, size_t len, bool encrypt) __attribute__((__warn_unused_result__)); -extern bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) __attribute__((__warn_unused_result__)); -extern bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) __attribute__((__warn_unused_result__)); +extern bool cipher_set_key(cipher_t *cipher, void *key, bool encrypt) ATTR_WARN_UNUSED; +extern bool cipher_set_key_from_rsa(cipher_t *cipher, void *rsa, size_t len, bool encrypt) ATTR_WARN_UNUSED; +extern bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) ATTR_WARN_UNUSED; +extern bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) ATTR_WARN_UNUSED; extern int cipher_get_nid(const cipher_t *cipher); extern bool cipher_active(const cipher_t *cipher); diff --git a/src/conf.h b/src/conf.h index 2d55edde..3cf677d5 100644 --- a/src/conf.h +++ b/src/conf.h @@ -43,7 +43,7 @@ extern list_t cmdline_conf; extern splay_tree_t *create_configuration(void); extern void init_configuration(splay_tree_t *); extern void exit_configuration(splay_tree_t **config_tree); -extern config_t *new_config(void) __attribute__((__malloc__)); +extern config_t *new_config(void) ATTR_MALLOC; extern void free_config(config_t *config); extern void config_add(splay_tree_t *config_tree, config_t *config); extern config_t *lookup_config(splay_tree_t *config_tree, const char *variable); diff --git a/src/connection.h b/src/connection.h index 75b7024d..3965127c 100644 --- a/src/connection.h +++ b/src/connection.h @@ -114,7 +114,7 @@ extern connection_t *everyone; extern void init_connections(void); extern void exit_connections(void); -extern connection_t *new_connection(void) __attribute__((__malloc__)); +extern connection_t *new_connection(void) ATTR_MALLOC; extern void free_connection(connection_t *c); extern void connection_add(connection_t *c); extern void connection_del(connection_t *c); diff --git a/src/digest.h b/src/digest.h index dba6ee44..82b46916 100644 --- a/src/digest.h +++ b/src/digest.h @@ -39,12 +39,12 @@ typedef struct digest digest_t; extern bool digest_open_by_name(digest_t *digest, const char *name, size_t maclength); extern bool digest_open_by_nid(digest_t *digest, int nid, size_t maclength); -extern digest_t *digest_alloc(void) __attribute__((__malloc__)); +extern digest_t *digest_alloc(void) ATTR_MALLOC; extern void digest_free(digest_t **digest); extern void digest_close(digest_t *digest); -extern bool digest_create(digest_t *digest, const void *indata, size_t inlen, void *outdata) __attribute__((__warn_unused_result__)); -extern bool digest_verify(digest_t *digest, const void *indata, size_t inlen, const void *digestdata) __attribute__((__warn_unused_result__)); -extern bool digest_set_key(digest_t *digest, const void *key, size_t len) __attribute__((__warn_unused_result__)); +extern bool digest_create(digest_t *digest, const void *indata, size_t inlen, void *outdata) ATTR_WARN_UNUSED; +extern bool digest_verify(digest_t *digest, const void *indata, size_t inlen, const void *digestdata) ATTR_WARN_UNUSED; +extern bool digest_set_key(digest_t *digest, const void *key, size_t len) ATTR_WARN_UNUSED; extern int digest_get_nid(const digest_t *digest); extern size_t digest_keylength(const digest_t *digest); extern size_t digest_length(const digest_t *digest); diff --git a/src/dropin.h b/src/dropin.h index a1fb6c1b..da10cd9a 100644 --- a/src/dropin.h +++ b/src/dropin.h @@ -73,9 +73,6 @@ extern int gettimeofday(struct timeval *, void *); #ifdef _MSC_VER -#define __attribute(args) -#define __attribute__(args) - #define PATH_MAX MAX_PATH #define strcasecmp _stricmp #define strncasecmp _strnicmp diff --git a/src/ecdh.h b/src/ecdh.h index bcd6b167..4cd8586f 100644 --- a/src/ecdh.h +++ b/src/ecdh.h @@ -29,8 +29,8 @@ typedef struct ecdh ecdh_t; #endif -extern ecdh_t *ecdh_generate_public(void *pubkey) __attribute__((__malloc__)); -extern bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared) __attribute__((__warn_unused_result__)); +extern ecdh_t *ecdh_generate_public(void *pubkey) ATTR_MALLOC; +extern bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared) ATTR_WARN_UNUSED; extern void ecdh_free(ecdh_t *ecdh); #endif diff --git a/src/ecdsa.h b/src/ecdsa.h index d06b9684..659d5596 100644 --- a/src/ecdsa.h +++ b/src/ecdsa.h @@ -26,13 +26,13 @@ typedef struct ecdsa ecdsa_t; #endif -extern ecdsa_t *ecdsa_set_base64_public_key(const char *p) __attribute__((__malloc__)); +extern ecdsa_t *ecdsa_set_base64_public_key(const char *p) ATTR_MALLOC; extern char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa); -extern ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) __attribute__((__malloc__)); -extern ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) __attribute__((__malloc__)); +extern ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) ATTR_MALLOC; +extern ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) ATTR_MALLOC; extern size_t ecdsa_size(ecdsa_t *ecdsa); -extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out) __attribute__((__warn_unused_result__)); -extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out) __attribute__((__warn_unused_result__)); +extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out) ATTR_WARN_UNUSED; +extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out) ATTR_WARN_UNUSED; extern bool ecdsa_active(ecdsa_t *ecdsa); extern void ecdsa_free(ecdsa_t *ecdsa); diff --git a/src/ecdsagen.h b/src/ecdsagen.h index 48cd25b9..1132dd6f 100644 --- a/src/ecdsagen.h +++ b/src/ecdsagen.h @@ -22,8 +22,8 @@ #include "ecdsa.h" -extern ecdsa_t *ecdsa_generate(void) __attribute__((__malloc__)); -extern bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) __attribute__((__warn_unused_result__)); -extern bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) __attribute__((__warn_unused_result__)); +extern ecdsa_t *ecdsa_generate(void) ATTR_MALLOC; +extern bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) ATTR_WARN_UNUSED; +extern bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) ATTR_WARN_UNUSED; #endif diff --git a/src/edge.h b/src/edge.h index 6d588fc9..3430eb12 100644 --- a/src/edge.h +++ b/src/edge.h @@ -42,7 +42,7 @@ typedef struct edge_t { extern splay_tree_t edge_weight_tree; /* Tree with all known edges sorted on weight */ extern void exit_edges(void); -extern edge_t *new_edge(void) __attribute__((__malloc__)); +extern edge_t *new_edge(void) ATTR_MALLOC; extern void free_edge(edge_t *e); extern void init_edge_tree(splay_tree_t *tree); extern void edge_add(edge_t *e); diff --git a/src/have.h b/src/have.h index 1d1bedfc..5d99cc23 100644 --- a/src/have.h +++ b/src/have.h @@ -61,6 +61,30 @@ #endif #endif +#ifdef HAVE_ATTR_MALLOC +#define ATTR_MALLOC __attribute__((__malloc__)) +#else +#define ATTR_MALLOC +#endif + +#ifdef HAVE_ATTR_NONNULL +#define ATTR_NONNULL __attribute__((__nonnull__)) +#else +#define ATTR_NONNULL +#endif + +#ifdef HAVE_ATTR_WARN_UNUSED_RESULT +#define ATTR_WARN_UNUSED __attribute__((__warn_unused_result__)) +#else +#define ATTR_WARN_UNUSED +#endif + +#ifdef HAVE_ATTR_FORMAT +#define ATTR_FORMAT(func, str, nonstr) __attribute__((format(func, str, nonstr))) +#else +#define ATTR_FORMAT(func, str, nonstr) +#endif + #ifdef HAVE_ALLOCA_H #include #elif defined(HAVE_NETBSD) diff --git a/src/list.h b/src/list.h index 511b64a4..e605ce10 100644 --- a/src/list.h +++ b/src/list.h @@ -45,7 +45,7 @@ typedef struct list_t { /* (De)constructors */ -extern list_t *list_alloc(list_action_t delete) __attribute__((__malloc__)); +extern list_t *list_alloc(list_action_t delete) ATTR_MALLOC; extern void list_free(list_t *list); extern list_node_t *list_alloc_node(void); extern void list_free_node(list_t *list, list_node_t *node); diff --git a/src/logger.h b/src/logger.h index e8e9a576..038f23ea 100644 --- a/src/logger.h +++ b/src/logger.h @@ -75,7 +75,7 @@ extern bool logcontrol; extern int umbilical; extern void openlogger(const char *ident, logmode_t mode); extern void reopenlogger(void); -extern void logger(debug_t level, int priority, const char *format, ...) __attribute__((__format__(printf, 3, 4))); +extern void logger(debug_t level, int priority, const char *format, ...) ATTR_FORMAT(printf, 3, 4); extern void closelogger(void); #endif diff --git a/src/meson.build b/src/meson.build index 484b514a..af2410d0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -11,10 +11,10 @@ cdata.set_quoted('SBINDIR', dir_sbin) cdata.set('HAVE_' + os_name.to_upper(), 1) -foreach attr : ['malloc', 'nonnull', 'warn_unused_result', 'packed'] +foreach attr : ['malloc', 'nonnull', 'warn_unused_result', 'packed', 'format'] if cc.has_function_attribute(attr) cdata.set('HAVE_ATTR_' + attr.to_upper(), 1, - description: '__attribute__(@0@)'.format(attr)) + description: '__attribute__((__@0@__))'.format(attr)) endif endforeach diff --git a/src/netutl.h b/src/netutl.h index 4aa15425..a86a859d 100644 --- a/src/netutl.h +++ b/src/netutl.h @@ -25,10 +25,10 @@ extern bool hostnames; -extern struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) __attribute__((__malloc__)); +extern struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) ATTR_MALLOC; extern sockaddr_t str2sockaddr(const char *address, const char *port); extern void sockaddr2str(const sockaddr_t *sa, char **address, char **port); -extern char *sockaddr2hostname(const sockaddr_t *sa) __attribute__((__malloc__)); +extern char *sockaddr2hostname(const sockaddr_t *sa) ATTR_MALLOC; extern int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b); extern int sockaddrcmp_noport(const sockaddr_t *a, const sockaddr_t *b); extern void sockaddrunmap(sockaddr_t *sa); diff --git a/src/node.h b/src/node.h index 5a138f89..0818a027 100644 --- a/src/node.h +++ b/src/node.h @@ -120,7 +120,7 @@ extern struct node_t *myself; extern splay_tree_t node_tree; extern void exit_nodes(void); -extern node_t *new_node(void) __attribute__((__malloc__)); +extern node_t *new_node(void) ATTR_MALLOC; extern void free_node(node_t *n); extern void node_add(node_t *n); extern void node_del(node_t *n); diff --git a/src/prf.h b/src/prf.h index 7e5e4e6d..2e60dff4 100644 --- a/src/prf.h +++ b/src/prf.h @@ -22,6 +22,6 @@ #include "system.h" -extern bool prf(const uint8_t *secret, size_t secretlen, uint8_t *seed, size_t seedlen, uint8_t *out, size_t outlen) __attribute__((__warn_unused_result__)); +extern bool prf(const uint8_t *secret, size_t secretlen, uint8_t *seed, size_t seedlen, uint8_t *out, size_t outlen) ATTR_WARN_UNUSED; #endif diff --git a/src/protocol.h b/src/protocol.h index fd1676cb..392a1fe8 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -80,7 +80,7 @@ extern ecdsa_t *invitation_key; /* Basic functions */ -extern bool send_request(struct connection_t *c, const char *format, ...) __attribute__((__format__(printf, 2, 3))); +extern bool send_request(struct connection_t *c, const char *format, ...) ATTR_FORMAT(printf, 2, 3); extern void forward_request(struct connection_t *c, const char *request); extern bool receive_request(struct connection_t *c, const char *request); diff --git a/src/rsa.h b/src/rsa.h index f7e9dbfa..8f0c1f68 100644 --- a/src/rsa.h +++ b/src/rsa.h @@ -27,12 +27,12 @@ typedef struct rsa rsa_t; #endif extern void rsa_free(rsa_t *rsa); -extern rsa_t *rsa_set_hex_public_key(const char *n, const char *e) __attribute__((__malloc__)); -extern rsa_t *rsa_set_hex_private_key(const char *n, const char *e, const char *d) __attribute__((__malloc__)); -extern rsa_t *rsa_read_pem_public_key(FILE *fp) __attribute__((__malloc__)); -extern rsa_t *rsa_read_pem_private_key(FILE *fp) __attribute__((__malloc__)); +extern rsa_t *rsa_set_hex_public_key(const char *n, const char *e) ATTR_MALLOC; +extern rsa_t *rsa_set_hex_private_key(const char *n, const char *e, const char *d) ATTR_MALLOC; +extern rsa_t *rsa_read_pem_public_key(FILE *fp) ATTR_MALLOC; +extern rsa_t *rsa_read_pem_private_key(FILE *fp) ATTR_MALLOC; extern size_t rsa_size(const rsa_t *rsa); -extern bool rsa_public_encrypt(rsa_t *rsa, const void *in, size_t len, void *out) __attribute__((__warn_unused_result__)); -extern bool rsa_private_decrypt(rsa_t *rsa, const void *in, size_t len, void *out) __attribute__((__warn_unused_result__)); +extern bool rsa_public_encrypt(rsa_t *rsa, const void *in, size_t len, void *out) ATTR_WARN_UNUSED; +extern bool rsa_private_decrypt(rsa_t *rsa, const void *in, size_t len, void *out) ATTR_WARN_UNUSED; #endif diff --git a/src/rsagen.h b/src/rsagen.h index a6616079..795153d5 100644 --- a/src/rsagen.h +++ b/src/rsagen.h @@ -22,8 +22,8 @@ #include "rsa.h" -extern rsa_t *rsa_generate(size_t bits, unsigned long exponent) __attribute__((__malloc__)); -extern bool rsa_write_pem_public_key(rsa_t *rsa, FILE *fp) __attribute__((__warn_unused_result__)); -extern bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp) __attribute__((__warn_unused_result__)); +extern rsa_t *rsa_generate(size_t bits, unsigned long exponent) ATTR_MALLOC; +extern bool rsa_write_pem_public_key(rsa_t *rsa, FILE *fp) ATTR_WARN_UNUSED; +extern bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp) ATTR_WARN_UNUSED; #endif diff --git a/src/splay_tree.h b/src/splay_tree.h index da1658a1..24645fa5 100644 --- a/src/splay_tree.h +++ b/src/splay_tree.h @@ -63,10 +63,10 @@ typedef struct splay_tree_t { /* (De)constructors */ -extern splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) __attribute__((__malloc__)); +extern splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) ATTR_MALLOC; extern void splay_free_tree(splay_tree_t *tree); -extern splay_node_t *splay_alloc_node(void) __attribute__((__malloc__)); +extern splay_node_t *splay_alloc_node(void) ATTR_MALLOC; extern void splay_free_node(splay_tree_t *tree, splay_node_t *node); /* Insertion and deletion */ diff --git a/src/subnet.h b/src/subnet.h index ad0a8b8d..016aa547 100644 --- a/src/subnet.h +++ b/src/subnet.h @@ -65,7 +65,7 @@ typedef struct subnet_t { extern splay_tree_t subnet_tree; extern int subnet_compare(const struct subnet_t *a, const struct subnet_t *b); -extern subnet_t *new_subnet(void) __attribute__((__malloc__)); +extern subnet_t *new_subnet(void) ATTR_MALLOC; extern void free_subnet(subnet_t *subnet); extern void init_subnets(void); extern void exit_subnets(void); diff --git a/src/xalloc.h b/src/xalloc.h index da74ce1f..96b9592b 100644 --- a/src/xalloc.h +++ b/src/xalloc.h @@ -23,7 +23,7 @@ #include "system.h" -static inline void *xmalloc(size_t n) __attribute__((__malloc__)); +static inline void *xmalloc(size_t n) ATTR_MALLOC; static inline void *xmalloc(size_t n) { void *p = malloc(n); @@ -34,7 +34,7 @@ static inline void *xmalloc(size_t n) { return p; } -static inline void *xzalloc(size_t n) __attribute__((__malloc__)); +static inline void *xzalloc(size_t n) ATTR_MALLOC; static inline void *xzalloc(size_t n) { void *p = calloc(1, n); @@ -55,7 +55,7 @@ static inline void *xrealloc(void *p, size_t n) { return p; } -static inline char *xstrdup(const char *s) __attribute__((__malloc__)) __attribute((__nonnull__)); +static inline char *xstrdup(const char *s) ATTR_MALLOC ATTR_NONNULL; static inline char *xstrdup(const char *s) { char *p = strdup(s); @@ -87,7 +87,7 @@ static inline int xvasprintf(char **strp, const char *fmt, va_list ap) { return result; } -static inline int xasprintf(char **strp, const char *fmt, ...) __attribute__((__format__(printf, 2, 3))); +static inline int xasprintf(char **strp, const char *fmt, ...) ATTR_FORMAT(printf, 2, 3); static inline int xasprintf(char **strp, const char *fmt, ...) { va_list ap; va_start(ap, fmt);