aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/libmdsclient/inbound.c4
-rw-r--r--src/libmdsserver/fd-table.h2
-rw-r--r--src/libmdsserver/hash-table.h2
-rw-r--r--src/libmdsserver/macros.h25
-rw-r--r--src/libmdsserver/util.c10
-rw-r--r--src/mds-clipboard.c2
-rw-r--r--src/mds-colour.c2
-rw-r--r--src/mds-kbdc/compile-layout.c3
-rw-r--r--src/mds-registry/registry.c4
-rw-r--r--src/mds-registry/slave.c4
-rw-r--r--src/mds-server/interceptors.c2
11 files changed, 47 insertions, 13 deletions
diff --git a/src/libmdsclient/inbound.c b/src/libmdsclient/inbound.c
index f2ea03c..019ed51 100644
--- a/src/libmdsclient/inbound.c
+++ b/src/libmdsclient/inbound.c
@@ -554,8 +554,8 @@ int libmds_mspool_initialise(libmds_mspool_t* restrict this)
this->messages = malloc(sizeof(libmds_message_t*));
if (this->messages == NULL)
return -1;
- if (sem_init(&(this->lock), 0, 1) < 0) goto fail; stage++;
- if (sem_init(&(this->semaphore), 0, 0) < 0) goto fail; stage++;
+ if (sem_init(&(this->lock), 0, 1) < 0) goto fail; else stage++;
+ if (sem_init(&(this->semaphore), 0, 0) < 0) goto fail; else stage++;
if (sem_init(&(this->wait_semaphore), 0, 0) < 0) goto fail;
return 0;
fail:
diff --git a/src/libmdsserver/fd-table.h b/src/libmdsserver/fd-table.h
index dfcb360..19d1f99 100644
--- a/src/libmdsserver/fd-table.h
+++ b/src/libmdsserver/fd-table.h
@@ -183,7 +183,7 @@ void fd_table_marshal(const fd_table_t* restrict this, char* restrict data);
* @return Non-zero on error, `errno` will be set accordingly.
* Destroy the table on error.
*/
-__attribute__((nonnull))
+__attribute__((nonnull(1, 2)))
int fd_table_unmarshal(fd_table_t* restrict this, char* restrict data, remap_func* remapper);
diff --git a/src/libmdsserver/hash-table.h b/src/libmdsserver/hash-table.h
index f9e4dec..1a3a26c 100644
--- a/src/libmdsserver/hash-table.h
+++ b/src/libmdsserver/hash-table.h
@@ -266,7 +266,7 @@ void hash_table_marshal(const hash_table_t* restrict this, char* restrict data);
* @return Non-zero on error, `errno` will be set accordingly.
* Destroy the table on error.
*/
-__attribute__((nonnull))
+__attribute__((nonnull(1, 2)))
int hash_table_unmarshal(hash_table_t* restrict this, char* restrict data, remap_func* remapper);
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h
index 80a0c25..f5c6808 100644
--- a/src/libmdsserver/macros.h
+++ b/src/libmdsserver/macros.h
@@ -656,7 +656,7 @@
* `strdup` wrapper that returns whether the allocation was not successful
*
* @param var:char* The variable to which to assign the duplicate
- * @param original:const char* The string to duplicate
+ * @param original:const char* The string to duplicate, may be `NULL`
* @return :int Evaluates to true if an only if the allocation failed
*/
#define xstrdup(var, original) \
@@ -673,6 +673,29 @@
/**
+ * `strdup` wrapper that returns whether the allocation was not successful
+ *
+ * This macro was added because GCC 6.1.1 warns of `original` is known to
+ * be nonnull, when using `xstrdup`.
+ *
+ * @param var:char* The variable to which to assign the duplicate
+ * @param original:const char* The string to duplicate, must not be `NULL`
+ * @return :int Evaluates to true if an only if the allocation failed
+ */
+#define xstrdup_nn(var, original) \
+ ((var = strdup(original)) == NULL)
+/*
+#define xstrdup_nn(var, original) \
+ ({ \
+ size_t _x_size = strlen(original); \
+ fprintf(stderr, "xstrdup_nn(%s, %s(“%s”=%zu))(=%zu) @ %s:%i\n", \
+ #var, #original, original, _x_size, _x_size + !!_x_size, __FILE__, __LINE__); \
+ (var = strdup(original)) == NULL; \
+ })
+*/
+
+
+/**
* `malloc` and `memcpy` wrapper that creates a duplicate of a pointer and
* returns whether the allocation was not successful
*
diff --git a/src/libmdsserver/util.c b/src/libmdsserver/util.c
index 14df3a9..a3e18a9 100644
--- a/src/libmdsserver/util.c
+++ b/src/libmdsserver/util.c
@@ -298,6 +298,13 @@ int strict_atoj(const char* str, intmax_t* value, intmax_t min, intmax_t max)
}
+#if defined(__GNUC__)
+/* GCC says strict_atouj is a candidate for the attribute ‘pure’,
+ * however the line `*value = r` means that it is not, at least
+ * if you only consider what GCC's manuals says about the attribute. */
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+#endif
/**
* A version of `atouj` that is strict about the syntax and bounds
*
@@ -334,6 +341,9 @@ int strict_atouj(const char* str, uintmax_t* value, uintmax_t min, uintmax_t max
*value = r;
return 0;
}
+#if defined(__GNUC__)
+# pragma GCC diagnostic pop
+#endif
#define __strict_y(Y, TYPE, PARA_TYPE, HYPER_Y, HYPER_TYPE) \
diff --git a/src/mds-clipboard.c b/src/mds-clipboard.c
index 30213ea..5d54f79 100644
--- a/src/mds-clipboard.c
+++ b/src/mds-clipboard.c
@@ -648,7 +648,7 @@ int clipboard_death(const char* recv_client_id)
int clipboard_add(int level, const char* time_to_live, const char* recv_client_id)
{
int autopurge = CLIPITEM_AUTOPURGE_UPON_CLOCK;
- uint64_t client = recv_client_id ? parse_client_id(recv_client_id) : 0;
+ uint64_t client = parse_client_id(recv_client_id);
clipitem_t new_clip;
fail_if (clipboard_purge(level, NULL));
diff --git a/src/mds-colour.c b/src/mds-colour.c
index 9179a61..f7a5722 100644
--- a/src/mds-colour.c
+++ b/src/mds-colour.c
@@ -767,7 +767,7 @@ int set_colour(const char* name, const colour_t* colour)
/* `colour_list_put` will store the name of the colour,
so we have to make a copy that will not disappear. */
- fail_if (xstrdup(name_, name));
+ fail_if (xstrdup_nn(name_, name));
/* Add or modify the colour. */
fail_if (colour_list_put(&colours, name_, colour));
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c
index b8d62f3..f585030 100644
--- a/src/mds-kbdc/compile-layout.c
+++ b/src/mds-kbdc/compile-layout.c
@@ -2563,7 +2563,8 @@ static int compile_subtree(mds_kbdc_tree_t* restrict tree)
case C(FUNCTION): c (function); break;
case C(MACRO): c (macro); break;
case C(ASSUMPTION):
- t ((includes_ptr == 0) && compile_subtree(tree->assumption.inner));
+ if (includes_ptr == 0)
+ fail_if (compile_subtree(tree->assumption.inner));
break;
case C(ASSUMPTION_HAVE): c (have); break;
case C(ASSUMPTION_HAVE_CHARS): c (have_chars); break;
diff --git a/src/mds-registry/registry.c b/src/mds-registry/registry.c
index 964b55f..77cd463 100644
--- a/src/mds-registry/registry.c
+++ b/src/mds-registry/registry.c
@@ -155,7 +155,7 @@ static int registry_action_add(int has_key, char* command, size_t command_key, u
void* address;
fail_if (xmalloc(address = list, 1, client_list_t));
/* Duplicate the protocol name so it can be accessed later. */
- if (xstrdup(command, command))
+ if (xstrdup_nn(command, command))
{
saved_errno = errno, free(list), errno = saved_errno;
fail_if (1);
@@ -240,7 +240,7 @@ static int registry_action_act(char* command, int action, uint64_t client, hash_
else if ((action == 0) && !has_key)
{
/* Add protocol to wait set of not present in the protocol table. */
- fail_if (xstrdup(command, command));
+ fail_if (xstrdup_nn(command, command));
command_key = (size_t)(void*)command;
if (hash_table_put(wait_set, command_key, 1) == 0)
if (errno)
diff --git a/src/mds-registry/slave.c b/src/mds-registry/slave.c
index 3d60437..b936c29 100644
--- a/src/mds-registry/slave.c
+++ b/src/mds-registry/slave.c
@@ -287,8 +287,8 @@ slave_t* slave_create(hash_table_t* restrict wait_set, const char* restrict recv
rc->wait_set = wait_set;
rc->client = parse_client_id(recv_client_id);
- fail_if (xstrdup(rc->client_id, recv_client_id));
- fail_if (xstrdup(rc->message_id, recv_message_id));
+ fail_if (xstrdup_nn(rc->client_id, recv_client_id));
+ fail_if (xstrdup_nn(rc->message_id, recv_message_id));
return rc;
diff --git a/src/mds-server/interceptors.c b/src/mds-server/interceptors.c
index ddaedd6..fccb0fa 100644
--- a/src/mds-server/interceptors.c
+++ b/src/mds-server/interceptors.c
@@ -141,7 +141,7 @@ void add_intercept_condition(client_t* client, char* condition, int64_t priority
else
{
/* Duplicate condition string. */
- fail_if (xstrdup(condition, condition));
+ fail_if (xstrdup_nn(condition, condition));
/* Grow the interception condition list. */
fail_if (xrealloc(conds, n + 1, interception_condition_t));