aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsserver
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
4 files changed, 36 insertions, 3 deletions
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) \