]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Compile with -Wsuggest-attribute=malloc.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 30 May 2023 22:11:14 +0000 (00:11 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 24 Dec 2023 21:37:00 +0000 (22:37 +0100)
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.

Makefile.real
audiod.c
audiod.h
mp4.c
mp4.h
net.c
net.h
ogg_afh_common.c
ogg_afh_common.h
send.h
send_common.c

index 21cef7c7518178589721c530d94e56908d25b7d2..d67c9bff98f15a57270d5f6c8ce101cf093b41c8 100644 (file)
@@ -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
index 0d8f039c768938bd563b7f928cb7a9aa0f2776ab..7c223995a9a29cec3c8e8ae5497c3be58655f63c 100644 (file)
--- 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 */
index dedb038fbf772848330b024b93efabce58c1c9d3..39beda1bd4223d145fb327f07be4c5e5d4845d94 100644 (file)
--- 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 f8515ca290681a271155e9749d903ea9214b9b13..5ca1307f680d366c155b2e98257ba807c5a4fb92 100644 (file)
--- 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 1618aa31d2cb49ccc3ae2182ddf8d7ef1f5c5f6f..c36a1f81db84bbe8c0f6a800f74a75f36cc2d93b 100644 (file)
--- 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 a24081f5123bd5a62236ff6d8202afc4e16c009b..9b3624428d5e8a0f63df7d814783df20afa54385 100644 (file)
--- 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 d206881c587b8ec185856e23e84bb26ecf032f45..33acfc890495087991c964397371e4edf9b574f1 100644 (file)
--- 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,
index 3a5c263cbc09169f15c973040ddc2e0118b27c9c..0a27a4acebc1652da03dea1573bf337eaf9c52a9 100644 (file)
@@ -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));
 }
index e0cf2d40c3ffb825c9f19338aa792558cb1c8742..03bf88b5794b0374fba493a79e502e4a89a686ca 100644 (file)
@@ -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 dec5b0db1381694fcb35a98785a50068cb1f6330..3407bc5c28a876f1fb5aca6e748368deb58afe0b 100644 (file)
--- 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);
index 26502cabd08376673b2c46b61ccffae400344274..8dc82e9cba42aecf027761c7682289fb0a9b6797 100644 (file)
@@ -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"