From: Andre Noll Date: Tue, 30 May 2023 22:11:14 +0000 (+0200) Subject: Compile with -Wsuggest-attribute=malloc. X-Git-Tag: v0.7.3~6 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=914ee19c1fd21834fe5f81260daafe76a4475290;p=paraslash.git Compile with -Wsuggest-attribute=malloc. We already employ this attribute extensively to help the compiler improve optimization. However, a few malloc-like functions were not yet marked with __malloc. Fix that and enable the warning to make sure that new malloc-like functions get marked. Since not all supported compilers know about this warning option, we need to check at compile time whether the option is supported. Thanks to the existing cc-option make(1) function, this is a simple one-liner for Makefile.real. --- diff --git a/Makefile.real b/Makefile.real index 21cef7c7..d67c9bff 100644 --- a/Makefile.real +++ b/Makefile.real @@ -157,6 +157,7 @@ cc-option = $(shell \ STRICT_CFLAGS += $(call cc-option, -Wformat-signedness) STRICT_CFLAGS += $(call cc-option, -Wdiscarded-qualifiers) +STRICT_CFLAGS += $(call cc-option, -Wsuggest-attribute=malloc) # To put more focus on warnings, be less verbose as default # Use 'make V=1' to see the full commands diff --git a/audiod.c b/audiod.c index 0d8f039c..7c223995 100644 --- a/audiod.c +++ b/audiod.c @@ -290,7 +290,7 @@ static int get_play_time_slot_num(void) * * \return A string that must be freed by the caller. */ -char *get_time_string(void) +__malloc char *get_time_string(void) { int ret, seconds = 0, length = stat_task->length_seconds; struct timeval *tmp, sum, sss, /* server stream start */ diff --git a/audiod.h b/audiod.h index dedb038f..39beda1b 100644 --- a/audiod.h +++ b/audiod.h @@ -15,7 +15,7 @@ extern int audiod_status; struct btr_node *audiod_get_btr_root(void); __malloc char *audiod_get_decoder_flags(void); void clear_and_dump_items(void); -char *get_time_string(void); +__malloc char *get_time_string(void); bool uid_is_whitelisted(uid_t uid); /* defined in audiod_command.c */ diff --git a/mp4.c b/mp4.c index f8515ca2..5ca1307f 100644 --- a/mp4.c +++ b/mp4.c @@ -1044,7 +1044,7 @@ free_moov: * function also returns NULL. Otherwise a copy of the tag value is returned * and the caller should free this memory when it is no longer needed. */ -char *mp4_get_tag_value(const struct mp4 *f, const char *item) +__malloc char *mp4_get_tag_value(const struct mp4 *f, const char *item) { for (unsigned n = 0; n < f->meta.count; n++) if (!strcasecmp(f->meta.tags[n].item, item)) diff --git a/mp4.h b/mp4.h index 1618aa31..c36a1f81 100644 --- a/mp4.h +++ b/mp4.h @@ -84,4 +84,4 @@ uint64_t mp4_get_duration(const struct mp4 *f); int mp4_open_meta(const struct mp4_callback *cb, struct mp4 **result); struct mp4_metadata *mp4_get_meta(struct mp4 *f); int mp4_update_meta(struct mp4 *f); -char *mp4_get_tag_value(const struct mp4 *f, const char *item); +__malloc char *mp4_get_tag_value(const struct mp4 *f, const char *item); diff --git a/net.c b/net.c index a24081f5..9b362442 100644 --- a/net.c +++ b/net.c @@ -190,7 +190,7 @@ failed: * \return In all cases the returned string is a allocated with malloc(3) and * has to be freed by the caller. */ -char *format_url(const char *url, int default_port) +__malloc char *format_url(const char *url, int default_port) { char host[MAX_HOSTLEN]; int url_port; diff --git a/net.h b/net.h index d206881c..33acfc89 100644 --- a/net.h +++ b/net.h @@ -25,7 +25,7 @@ char *parse_cidr(const char *cidr, char *addr, ssize_t addrlen, int32_t *netmask); char *parse_url(const char *url, char *host, ssize_t hostlen, int32_t *port); -char *format_url(const char *url, int default_port); +__malloc char *format_url(const char *url, int default_port); const char *stringify_port(int port, const char *transport); int lookup_address(unsigned l4type, bool passive, const char *host, diff --git a/ogg_afh_common.c b/ogg_afh_common.c index 3a5c263c..0a27a4ac 100644 --- a/ogg_afh_common.c +++ b/ogg_afh_common.c @@ -365,7 +365,7 @@ struct oac_custom_header { * * \sa \ref oac_custom_header_init(). */ -struct oac_custom_header *oac_custom_header_new(void) +__malloc struct oac_custom_header *oac_custom_header_new(void) { return zalloc(sizeof(struct oac_custom_header)); } diff --git a/ogg_afh_common.h b/ogg_afh_common.h index e0cf2d40..03bf88b5 100644 --- a/ogg_afh_common.h +++ b/ogg_afh_common.h @@ -5,7 +5,7 @@ * handlers that use the ogg container format. */ -struct oac_custom_header *oac_custom_header_new(void); +__malloc struct oac_custom_header *oac_custom_header_new(void); void oac_custom_header_init(int serial, struct oac_custom_header *h); int oac_custom_header_append(ogg_packet *op, struct oac_custom_header *h); void oac_custom_header_flush(struct oac_custom_header *h); diff --git a/send.h b/send.h index dec5b0db..3407bc5c 100644 --- a/send.h +++ b/send.h @@ -196,7 +196,7 @@ void init_sender_status(struct sender_status *ss, const struct lls_opt_result *listen_address_opt_result, int default_port, int max_clients, int default_deny); void free_sender_status(const struct sender_status *ss); -char *generic_sender_status(struct sender_status *ss, const char *name); +__malloc char *generic_sender_status(struct sender_status *ss, const char *name); void generic_com_allow(struct sender_command_data *scd, struct sender_status *ss); void generic_com_deny(struct sender_command_data *scd, @@ -204,7 +204,7 @@ void generic_com_deny(struct sender_command_data *scd, void generic_com_on(struct sender_status *ss, unsigned protocol); void generic_acl_deplete(struct list_head *acl); void generic_com_off(struct sender_status *ss); -char *generic_sender_help(void); +__malloc char *generic_sender_help(void); struct sender_client *accept_sender_client(struct sender_status *ss); int send_queued_chunks(int fd, struct chunk_queue *cq); int parse_fec_url(const char *arg, struct sender_command_data *scd); diff --git a/send_common.c b/send_common.c index 26502cab..8dc82e9c 100644 --- a/send_common.c +++ b/send_common.c @@ -181,7 +181,7 @@ void free_sender_status(const struct sender_status *ss) * * \return The string printed in the "si" command. */ -char *generic_sender_status(struct sender_status *ss, const char *name) +__malloc char *generic_sender_status(struct sender_status *ss, const char *name) { char *clnts = NULL, *ret, *addr = NULL; struct sender_client *sc, *tmp_sc; @@ -413,7 +413,7 @@ warn: * \return A dynamically allocated string containing the help text for * a paraslash sender. */ -char *generic_sender_help(void) +__malloc char *generic_sender_help(void) { return make_message( "usage: {on|off}\n"